On 7 kesä, 22:02, Joakim Hove <joakim.h...@gmail.com> wrote:
> Hello,
>
> I have the following (schematic) situation:
>
> Class Table1(models.model):
> ....
> ....
>
> Class Table2(models.model):
> ....
> ....
>
> class Table3(models.model):
> table1_key = models.ForeignKey( Table1 )
> table2_key = models.ForeignKey( Table2 )
> .....
>
> Now, I want the two foreign keys in Table3 (in combination) to be a
> unique id, i.e. it should be illegal to have several entries in Table3
> pointing to the same combination of Table1 and Table2 keys. This
> should be doable?!
>
> Best Regards
>
> Joakim Hove
Use unique_together:
http://docs.djangoproject.com/en/dev/ref/models/options/
class Table3(models.Model):
...
class Meta:
unique_together = ("table1_key", "table2_key")
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---