python - django models dependancy between two classes -


this question has answer here:

i have 2 models in django app, both models contain multiple instances of other class. eg) topic can contain many books, , book may belong many topics. so, both must have manytomanyfield of other. code:

class topic(models.model):     books = models.manytomanyfield(book)  class book(models.model):     topics = models.manytomanyfield(topic) 

now problem is, error 'book' not defined. how rid of this?

pass name of model string manytomanyfield instead of model itself, see here (foreignkey behaves same way).

code:

class topic(models.model):     books = models.manytomanyfield('book')  class book(models.model):     topics = models.manytomanyfield('topic') 

edit:

i blindly answered without noticing same thing daniel. need have relationship defined in 1 of models, not both ways.


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 -

thorough guide for profiling racket code -