Describe the polymorphic relationship of Django -


tell me how describe connection: enter image description here

there table in there can different types of records (type1, type2 or type3).

models.py

from django.db import models django.contrib.contenttypes.fields import genericforeignkey, genericrelation django.contrib.contenttypes.models import contenttype  class general(models.model):     field1 = models.charfield(max_length=512, blank=true, null=true)     field2 = models.charfield(max_length=512, blank=true, null=true)     content_type = models.foreignkey(contenttype)     object_id = models.positiveintegerfield()     content_object = genericforeignkey('content_type', 'object_id')      class meta:         db_table = 'general'    class type1(models.model):     name = genericrelation(product)     address = models.charfield(max_length=512, blank=true, null=true)     number = models.charfield(max_length=256, blank=true, null=true)      class meta:         db_table = 'type1' 

how make connection , choose want type in type, example type2?

this looks correct except line:

name = genericrelation(product) 

should be:

name = genericrelation(general) 

in order form correct reverse generic relation.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -