Hi, I am beginner in Django. I need to enforce the rule when creating or modifying the record related to other records from another table in the admin mode. I have the following model:
class Location(models.Model): location = models.CharField('Location code', max_length=3, primary_key=True) name = models.CharField('Location name', max_length=50) class IngrCodeSel(models.Model): code = models.CharField('Ingredient code', max_length=5, primary_key=True) location = models.ForeignKey(Location) class IngrDetail(models.Model): code = models.ForeignKey(IngrCodeSel) location = models.ForeignKey(Location) description = models.CharField('Description', max_length=50) tradename = models.CharField('Tradename', max_length=50) In human language. There are few locations with unique code (say physical storehouses/factories in different countries) -- class Location. No problem with setting the initial values (less then 10 locations). Because of historical reasons, factories at the location use their local names of ingredients used for their production -- class IngrDetail. Fortunately, the codes of ingredients are unified throughout all locations. The allowed codes are captured via model IngrCodeSel. The purpose of the location in this table is to choose the prefered detail from the IngrDetail with the same code. However,... Some ingredients are used only on a subset of locations. This way the IngrCodeSel cannot be set to any code from Location, but only to the code for which there is the record in IngrDetail. How this restriction should be implemented in the admin mode of Django? Also, how can I ensure that there is at most one record for the combined key code+location in IngrDetail? Can you see any flaw in the model? Thanks for your help, Petr -- 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.