django - Isn't foreign key to contenttype sufficient? -


in django, have contenttype model. consider have models a, b , c.

class a(models.model):   field1 = models.booleanfield(default=true)   c = models.onetoonefield(myapp.c)  class b(models.model):   field2 = models.charfield()  class c(models.model):   limits = models.q(app_label=u'students', model=u'a') | \              models.q(app_label=u'myapp', model=u'b')   content_type = models.foreignkey(contenttype, limit_choices_to=limits) 

now if have object of c c1 content_type a, can access c1.a or c1.a.field1 if there exist object of refers c1.
so, why need genericforeignkey if can access a through c1.

also if call, c2.b.field2 if c2 object of c content_type b?

as commented knbk, should choose between onetoonefield c , genericforeignkey on c. having both redundant. generic relation can used in model , b enable reverse querying.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -