python - Django modelling - using the right relationships -


i want model 'model' have set (zero or more) of 'attribute's. should able access these 'attribute's. single 'attribute' has 1 'model'.

'model' has 0 or more 'objects'. should able access these 'object's. single 'object' has 1 'model'. 'object' inherit 'attribute's of it's 'model'.

i'm not sure how create these models in django.

here have far:

class model(models.model):     #  class attribute(models.model):     model = models.foreignkey(model)  class object(models.model):     model = models.foreignkey(model) 

update

when try make 'object' object, error:

column myproject_object.model_id not exist 

similarly, if try make 'model' object. error:

null value in column "attributes_id" violates not-null constraint 

this relation called many-to-many relationship , django has implemented in orm.

 class child(models.model):      # [...]   class parent(models.model):      children = models.manytomanyfield(model) 

you can access in way

 parent = parent()  parent.save()  parent.children.all() 

django create automatically relation in database, highly recommend read django documentation many-to-many relation.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -