python - Abstracting Exisiting Django Models -


i've got 2 models in django application have same fields, different types of information stored in each.

for example:

class a(models.model)     field_a =  models.charfield(primary_key = true, max_length = 24)     field_b =  models.charfield(primary_key = true, max_length = 24)  class b(models.model)     field_a =  models.charfield(primary_key = true, max_length = 24)     field_b =  models.charfield(primary_key = true, max_length = 24) 

it seems make sense contain these in abstract model , have these 2 classes sub-classes. assuming this, without needing make db modifications, django isn't able find fields of models longer.

could offer advice?

if create new abstract class won't interfere database. can see in documentation https://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-classes abstract classes python classes without database impact.

your code looks this:

class parent(models.model)     field_a =  models.charfield(primary_key = true, max_length = 24)     field_b =  models.charfield(primary_key = true, max_length = 24)      class meta:         abstract = true  class a(parent)     pass  class b(parent)     pass 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

React Native allow user to reorder elements in a scrollview list -

multithreading - Exception in Application constructor -