[patch]: Remove restriction on string name for relationship fields.
|Reported by:||Eric Van Dewoestine <ervandew@…>||Owned by:||adrian|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Patch based on development version 4051.
As described in the many-to-one relationships doc http://www.djangoproject.com/documentation/model_api/#many-to-one-relationships, django currently has the following restriction:
If you need to create a relationship on a model that has not yet been defined, you can use the name of the model, rather than the model object itself: ... Note, however, that you can only use strings to refer to models in the same models.py file -- you cannot use a string to reference a model in a different application, or to reference a model that has been imported from elsewhere.
The attached patch removes this restriction allowing one to do something like:
class Car(models.Model): manufacturer = models.ForeignKey('mysite.myotherapp.models.Manufacturer')