hi! I'm putting together a simple model in Django as an example for a large project. I'm attempting to set up the models in an efficient manner with as little redundancy as possible (none).
What I'm attempting to do is use unique_together across 2 classes which are linked through their primary key fields, with the unique_together referencing a field from each table which are not the primary keys. Is it possible to use unique_together across classes like this? If not, what alternative could I use that's clean and efficient? The rules that need to be adherred to within the model are as follows: 1.Survey's have many Lots. 2.Within a Survey, Lot numbers must be unique. 3.Lot's have many Lines. 4.Within a Survey, Line numbers must be unique. The models are posted below with the fields in question in bold. class Survey(models.Model): survey = models.IntegerField(primary_key=True, unique = True) class Meta: ordering = ["survey"] db_table='survey' class Lot(models.Model): lot_id = models.AutoField(primary_key=True, unique = True) lot_number = models.IntegerField() survey = models.ForeignKey(Survey, db_column ='survey') class Meta: ordering = ["lot_number"] db_table='lot' unique_together = ("lot_number", "survey") class Line(models.Model): line_id = models.AutoField(primary_key=True, unique = True) lot_id = models.ForeignKey(Lot, db_column='lot_id') line_number = models.IntegerField() class Meta: ordering = ["line_number"] db_table='line' unique_together =[("Lot.survey"), ("line_number")] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---