Skip to content

Way to sort via related objects? #7

@rlafuente

Description

@rlafuente

So far I couldn't find a way to sort through a related object's field.
Quick and dirty example:

class Blog(models.Model):
    name = models.CharField()
    type = models.CharField()

class Entry(models.Model):
    name = models.CharField()
    blog = models.ForeignKey(Blog)

And i have a table for Entries with three headers: Entry name, Blog name and Blog type.
I can sort the table by Entry name and Blog name, but not by Blog type. If i try

{% anchor 'blog.type' %}

It comes up with a TemplateSyntaxError:
Caught an exception while rendering: missing FROM-clause entry for table "blog"
LINE 1: ...ND NOT ("testapp_entry"."id" IN (110))) ORDER BY "blog...

I'm wondering if there's a bug in here or if it's simply not implemented. A
pointer of what code to check would be great, i could try and fix/add it
myself. I'm betting that this can be accomplished by tweaking
templatetags/sorting_tags.py, but i can't discern how it could be done.

By the way, awesome extension! It was such a pleasure doing away with my hardcoded sorting code :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions