> class Category(models.Model):
>     name = models.CharField(maxlength=50, unique=True)
> 
> class Theme(models.Model):
>     category = models.ForeignKey(Category)
>     name = models.CharField(maxlength=50, unique=True)
> 
> And an example of what I'd like:
> 
> This obviously doesn't work because if I try to create two themes with
> the same name but in a different category (using the Admin app), it'll
> complain that a theme with the same name already exists.
> 
> Can anyone help me with solving this problem?

http://www.djangoproject.com/documentation/model-api/#unique-together

class Theme(models.Model):
        category = models...
        name = models... # without unique constraint
        class Meta:
                unique_together = (
                        ("category", "name"),
                        )

-tim




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to