Reputation: 26565
I have this model:
class blog(models.Model):
user = models.ForeignKey(User)
mail = models.EmailField(max_length=60, null=False, blank=False)
name = models.CharField(max_length=60, blank=True, null=True)
I want that (user,email) are unique togheter. For example:
This is allowed:
1, [email protected], myblog
2, [email protected], secondblog
This is NOT allowed:
1, [email protected], myblog
1, [email protected], secondblog
Is this possible in Django ?
Upvotes: 0
Views: 180
Reputation: 188194
It's possible, see: model options,
http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together
class Answer(models.Model):
user = models. ...
email = models. ...
# ...
class Meta:
unique_together = (("user", "email"),)
Upvotes: 7