[Fixed]-Django overriding model save method sets unspecified fields to NULL

0👍

I believe the answer for your question can be found here:

Automatic creation date for django model form objects?

You want to use those, because Django can set creation and modification dates for you automatically without any additional interactions needed.

models.DateTimeField(auto_now_add=True)
models.DateTimeField(auto_now=True)

As for the slug, shorten your save() method to:

def save(self, *args, **kwargs):
    self.slug = slugify(self.name)
    super(eiysTblGroup, self).save(*args, **kwargs)
👤Nhor

1👍

Obviously, my erroneous part is this in view:

group = eiysTblGroup(id = group_id )

I’m not sure how I made such a silly mistake.
The correct form should be:

group = eiysTblGroup.objects.get(id = group_id )

Then it works correctly…

Leave a comment