Django - Custom save method in model

Viewed 7444

(Using Django 1.11.5)

Traditionally, I've always created a model like so:

class Animal(models.Model):
    is_hungry = models.BooleanField(default=True)

Then make changes like so:

animal = Animal()
animal.save()

animal.is_hungry = True
animal.save()

Recently, I saw a friend define a model with a custom save method:

class Animal(models.Model):
    is_hungry = models.BooleanField(default=True)

    def feed_animal(self):
        self.is_hungry = False
        self.save()

And calling this method appears to work as expected:

>>> from testapp.models import Animal
>>> a = Animal()
>>> a.save()
>>> a.is_hungry
True
>>>
>>> a.feed_animal()
>>> a.is_hungry
False

Are there any benefits/drawbacks in defining such a custom save method in the model definition? Is there any reason to prefer calling .save() on the object directly?

2 Answers
Related