Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango-nonrel sorting by foreignkey
    primarykey
    data
    text
    <p>Is there a way of returning items from a database in django-nonrel, using 'order_by' on a foreignkey?</p> <p>Full details are as follows:</p> <pre> #Models.py class Post(models.Model): article = models.TextField(help_text='Paste or type HTML in here') pub_date = models.DateField() .... class TagItems(models.Model): title = models.CharField(max_length=200) .... class TagRel(models.Model): the_post = models.ForeignKey('Post') the_tag = models.ForeignKey('Tag') </pre> <p>TagRel defines a ManytoMany relationship between Post and TagItems classes.</p> <p>I am wanting to get a list of articles for each tag.</p> <pre> #Desire output My tag -my first post -my second post My second tag - my other post - another post </pre> <p>All is good so far, as I use the following to filter the data:</p> <pre> def tagged_posts(): tag_items = TagItems.objects.all() li =[] for item in tag_items: tag_rel_item = TagRel.objects.filter(the_tag__pk = item.pk) li.append(tag_rel_item) return {'list_of_objects': li} </pre> <p>I am using db-indexer to define the filter part of the query in db-indexes.py. All this works fine but I want to order my posts by publication dates.</p> <p>Django docs tell me to use:</p> <pre> TagRel.objects.filter(the_tag__pk = item.pk).order_by('the_tag__pub_date') </pre> <p>But the order_by('the_tag__pub_date') part does not appear to be supported by django-nonrel.</p> <p>The following also works in normal Django:</p> <pre> TagRel.objects.filter(the_tag__pk = item.pk).order_by('the_post') </pre> <p>This works because the Posts are already sorted by date in the model.</p> <p>But this also does not appear to work in django-nonrel.</p> <p>So my question is how do I return my posts ordered by date (latest>oldest)?</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload