python - Django - Multiple optional ForeignKey -
class truc(models.model): name = models.charfield(max_length=50, unique=true) machin1 = models.foreignkey(machin1, blank=true, null=true) machin2 = models.foreignkey(machin2, blank=true, null=true) machin3 = models.foreignkey(machin3, blank=true, null=true)
i truc
linked 1 machin
, either machin1
either machin2
or machin3
.
only 1 link, kind of validation:
machin1 xor machin2 xor machin3
if ever linked 1 use generic relation:
class truc(models.model): name = models.charfield(max_length=50, unique=true) content_type = models.foreignkey(contenttype) object_id = models.positiveintegerfield() machin_object = generic.genericforeignkey('content_type', 'object_id')
Comments
Post a Comment