V
V
Vladimir Kuts2016-06-08 14:51:02
Django
Vladimir Kuts, 2016-06-08 14:51:02

Delete object via parent method?

There is a certain model in which the delete method is overridden. For example something like:

class SomeModel(SomeParent):
     deleted = models.BooleanField(default=False)

     def delete(self):
          self.deleted = True
          self.save()

I'm in the console and I want to delete an object:
>>> my_obj = SomeModel.object.get(pk=some_pk)
>>> my_obj.delete()

Naturally, the object is not deleted, but only its field changes. The object itself remains.
How do I still remove the object from the console? Write a new class with inheritance of the parent model (for the parent model, say, this method works properly), or something else?
The object is already in the console. And I want to remove it. parent is not available to me, as far as I understand:
>>> 'parent' in dir(my_obj)
False

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Melnikov, 2016-06-08
@fox_12

Try models.Model.delete(my_obj)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question