#13241 closed (fixed)
order_with_respect_to fails on a relationship on a model that has not yet been defined
Reported by: | Goldan | Owned by: | Gabriel Grant |
---|---|---|---|
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 (last modified by )
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"города"
Attachments (5)
Change History (11)
comment:1 by , 15 years ago
Description: | modified (diff) |
---|
comment:2 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 14 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
I've attached a patch with a test which fixes the bug, but since this is the first patch I've submitted to django, I'm not sure what the next step is to move it forward...
If anyone has any comments on the patch, I'd love to hear them.
Thanks!
-Gabriel
by , 14 years ago
Attachment: | 13241_unittest.diff added |
---|
doctest moved to unittest at the request of Alex Gaynor
comment:4 by , 14 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
(reformatted description, please use the 'Preview' button)