On Sun, 2009-01-18 at 02:40 -0800, Konstantin wrote: > Hello! > > First of all I want to apologize for maybe very basic question, but I > newbie in django and web coming from c/c++ world. > > I have two models: > > class Box(models.Model): > description = models.CharField(max_length=250) > id = models.IntegerField(primary_key=True) > > def __unicode__(self): > return self.description > > class Item(models.Model): > title = models.CharField(max_length=500) > box = models.ForeignKey(Box) > label = models.IntegerField() > > def __unicode__(self): > return self.title > > What I want is to enforce in some way uniqueness of pair (label, box) > for every item. So there may be items with the same label but they > must belong to different boxes.
Have a look at unique_together: http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together Right now, that is only enforced by the admin interface, however. True model-level validation is something we're working on for Django 1.1. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---