Opened 15 years ago
Last modified 14 years ago
#13241 closed
order_with_respect_to fails on a relationship on a model that has not yet been defined — at Initial Version
Reported by: | Goldan | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | order_with_respect_to | |
Cc: | Goldan | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If I specify 'order_with_respect_to' on a field linked to a model that hasn't been defined yet, I get the following error:
<...>File "/usr/lib/python2.6/dist-packages/django/db/models/base.py", line 223, in _prepare
setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.name.lower(), curry(method_get_order, cls))
AttributeError: 'str' object has no attribute 'get_location_order'
When I swap declarations of Location and City models, the error disappears.
Here is the code:
class Location(TimeStampedModel):
Single location on a map, e.g. building.
address = models.CharField(u"адрес", max_length=75, help_text=u"Улица, корпус, дом")
city = models.ForeignKey('City', related_name="locations", verbose_name=u"город")
metro_stations = models.ManyToManyField('MetroStation', related_name="locations", verbose_name=u"ближайшие станции метро", blank=True, null=True)
class Meta:
verbose_name = u"адрес"
verbose_name_plural = u"адреса"
order_with_respect_to = 'city'
class City(TimeStampedModel):
A city.
name = models.CharField(u"название", max_length=30)
class Meta:
verbose_name = u"город"
verbose_name_plural = u"города"