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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -