views:

38

answers:

2

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:

This is NOT allowed:

Is this possible in Django ?

+2  A: 

Meta.unique_together

Ignacio Vazquez-Abrams
+7  A: 

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"),)
The MYYN