class ExternalFriends(models.Model):
external_user = models.ForeignKey(User)
name = models.CharField(max_length=20, null=False, blank=False, db_index=True)
external_account_id = models.CharField(max_length=200, null=True, blank=True, db_index=T
rue)
So let's say开发者_开发技巧 I want all 3 fields to be "unique_together". How can I do that?
Use the Meta option unique_together
. This takes a tuple (or tuples) describing sets of columns that should be considered unique together.
The model would look like this:
class ExternalFriends(models.Model):
# columns
class Meta:
unique_together = ('external_user', 'name', 'external_account_id'),
精彩评论