I'm having problems with ordering based on related fields that may be
a clone of the issue brought up in ticket 1576 (http://
code.djangoproject.com/ticket/1576), though because that problem was
so old and the ticket was closed I wasn't sure where I should bring
this up. Also, it could just be my stupidity (I'm still new to
Django). I'm using 0.96.

----- structure/models.py
class Issue(models.Model):
    (...)
    pub_date = models.DateField('Publication date', unique=True)
    (...)

    class Meta:
        ordering = ['-pub_date']
-----

----- stories/models.py
class Story(models.Model):
    (...)
    issue = models.ForeignKey(Issue)
    (...)

    class Meta:
        verbose_name_plural = "Stories"
        ordering        = ['issue']
-----

Returns the error: "OperationalError at /admin/stories/story/ (1054,
"Unknown column 'structure_issue.-pub_date' in 'order clause'")"

SQL:
'SELECT
`stories_story`.`id`,`stories_story`.`head`,`stories_story`.`deck`,`stories_story`.`slug`,`stories_story`.`section_id`,`stories_story`.`issue_id`,`stories_story`.`content`,`stories_story`.`summary`,`stories_story`.`photo`,`stories_story`.`caption`,`stories_story`.`photographer_id`,`stories_story`.`section_order`,`structure_section`.`id`,`structure_section`.`name`,`structure_section`.`short_name`,`structure_section`.`slug`,`structure_issue`.`id`,`structure_issue`.`volume_id`,`structure_issue`.`issue`,`structure_issue`.`extra`,`structure_issue`.`pub_date`,`structure_issue`.`sections_id`,`structure_issue`.`is_published`,`structure_volume`.`id`,`structure_volume`.`volume`,`structure_flatplanorder`.`id`,`structure_flatplanorder`.`name`,`structure_flatplanorder`.`section1_id`,`structure_flatplanorder`.`section2_id`,`structure_flatplanorder`.`section3_id`,`structure_flatplanorder`.`section4_id`,`structure_flatplanorder`.`section5_id`,`structure_flatplanorder`.`section6_id`,`structure_flatplanorder`.`section7_id`,`structure_flatplanorder`.`section8_id`,`structure_flatplanorder`.`section9_id`,`structure_flatplanorder`.`section10_id`,`structure_flatplanorder`.`section11_id`,`structure_flatplanorder`.`section12_id`,`structure_flatplanorder`.`section13_id`,`structure_flatplanorder`.`section14_id`,`structure_flatplanorder`.`section15_id`,`structure_flatplanorder`.`section16_id`,`structure_section5`.`id`,`structure_section5`.`name`,`structure_section5`.`short_name`,`structure_section5`.`slug`
FROM `stories_story` , `structure_section`, `structure_issue`,
`structure_volume`, `structure_flatplanorder`, `structure_section`
`structure_section5` WHERE `stories_story`.`section_id` =
`structure_section`.`id` AND `stories_story`.`issue_id` =
`structure_issue`.`id` AND `structure_issue`.`volume_id` =
`structure_volume`.`id` AND `structure_issue`.`sections_id` =
`structure_flatplanorder`.`id` AND
`structure_flatplanorder`.`section1_id` = `structure_section5`.`id`
ORDER BY `structure_issue`.`-pub_date` ASC'

It seems as though Django's not recognizing its own ordering syntax
when attempting to sort objects based on a related object's ordering.
I should also mention that if I sort Issue by ['pub_date'] and Story
by ['-issue'] everything works fine. I'm still willing to do that as a
workaround, but I figured there might be a lot of instances where
that's either not ideal or impossible.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to