Python object not returned when saving to database

models.py

class AppUser(models.Model):
    name = models.CharField(max_length=30)
    last_logon = models.DateTimeField(auto_now=True)

views.py

class SomeView(View):
    def get(self, request, *args, **kwargs):
        appuser = AppUser(name="Some Person").save()

works perfectly!

So im just not sure if this is working as intended. But if I use the code shown above the python appuser object = None

However if I break it down into 2 statements like this ;

appuser = AppUser(name="Some Person")
appuser.save()

so it seems like simply instantiating the object will returns as expected but the save() does not return or returns None.

Is this by design? Took me forever to find this bug hidden is the bowels of my code :frowning:

Yes this is by design.

While I can’t quickly find any reference that specifies that this is the case, if you look at the source for the save method in Model, you’ll see that it doesn’t return a value. Also, if you look at the docs for Overriding predefined model methods where they show a sample of overriding a save method, their sample doesn’t return a value.

Someone with more background and history with Django would need to answer “why”, if you’re really curious you could search the tickets to see if it was ever raised as an issue.