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
- [Answered ]-Filtering dropdown queryset in Django view
- [Answered ]-Django LFS 0.10 No default admin user
- [Answered ]-Django RegexValidator fails on empty string
- [Answered ]-Django model A can has only one instance of model B
Source:stackexchange.com