[patch] Improve support for mutually-referential models
|Reported by:||Owned by:||Adrian Holovaty|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
ForeignKey and other related model fields allow recursive relationships; however, there can be problems when dealing with mutually referential models.
For example, consider a user class and a series of articles:
class User(models.Model): saved_articles = models.ManyToManyField('Article') # ... class Article(models.Model): author = models.ForeignKey(User) # ...
It doesn't make much sense for Users and Articles to be stored in the same
By using dotted-notation (app_name.model_name), it should be
possible to reference across models.py files when recursive import
statements would otherwise cause problems.
class User(models.Model): saved_articles = models.ManyToManyField('articles.Article') # ...
class Article(models.Model): author = models.ForeignKey('accounts.User') # ...
Attached patch adds this functionality and provides documentation.
Change History (12)
comment:1 Changed 10 years ago by
|Summary:||Improve support for mutually-referential models → [patch] Improve support for mutually-referential models|