4👍
✅
Take a look at the Meta class option unique_together
You could do it this way:
class Author(models.Model):
first_name = models.CharField()
last_name = models.CharField()
def _get_full_name(self):
return '{0} {1}'.format(self.first_name, self.last_name)
full_name = property(_get_full_name)
class Meta:
unique_together = ("first_name", "last_name")
The advantage is that this is enforced at the DB level with the proper UNIQUE SQL statements.
- [Django]-Automatically import all db tables in manage.py shell
- [Django]-Django send_mail results in Error 60, Operation Timed Out on Mac OSX
- [Django]-ManytoMany Tags in HTML Template
- [Django]-Django Rest Framework – Nested Serializer are lazy loaded?
- [Django]-ImportError No module named blog
Source:stackexchange.com