[Answered ]-Why overriden save() method is bypassed?

2πŸ‘

βœ…

I think what you want instead is:

class Points(TimeStampedModel):
    # ...
    class Meta:
        unique_together = ('benef_card', 'spendable_at')

Then you don’t need to override save β€” the uniqueness will be handled by a DB constraint and it is generally the way to go. This approach is better because save is not always called (example: bulk operations) so you might get different behavior across your app.

You might also want to check out update_or_create which just returns an object with attributes you need, creating it if it doesn’t exist.

πŸ‘€Ivan

0πŸ‘

You could use Django signals instead to check before save.

πŸ‘€Gocht

Leave a comment