| Name | rkadeFR |
|---|---|
| Email Address | n/a |
| Posts | 2 |
-
- 2012-06-25 09:40:33
- Re: [Queryset] Sorting only the children
- Board » Django » Models
-
I've found the solution.
I have to put a class Meta on the models for my experience, with ordering = ['-end_date'].
If anyone need this solution... share it
-
- 2012-06-21 18:41:22
- [Queryset] Sorting only the children
- Board » Django » Models
-
Hello everyone,
I'm new to django and to this forum btw.
I am developing a very simple application to handle my resume.
So there is only two models so far : "Category", and "Experience"
Experience has a foreign key to Category.
And I would like to retrieve in a view all the Category with their experiences but would like to sort the experience by the field "end_date".
So I tried many ways like :
>>> Category.objects.all().order_by( 'experience__end_date' ).distinct()
[<Category: Compétences>, <Category: Centre d'intérêts>, <Category: Expériences>, <Category: Formation>, <Category: Expériences>, <Category: Formation>, <Category: Expériences>, <Category: Expériences>, <Category: Expériences>, <Category: Formation>, <Category: Formation>]
>>> Category.objects.all().order_by( 'experience__end_date' ).distinct( 'name' )
[<Category: Compétences>, <Category: Centre d'intérêts>, <Category: Expériences>, <Category: Formation>, <Category: Expériences>, <Category: Formation>, <Category: Expériences>, <Category: Expériences>, <Category: Expériences>, <Category: Formation>, <Category: Formation>]
>>> Category.objects.all().order_by( 'experience__end_date' ).distinct( 'experience__end_date' )
[<Category: Compétences>, <Category: Centre d'intérêts>, <Category: Expériences>, <Category: Formation>, <Category: Expériences>, <Category: Formation>, <Category: Expériences>, <Category: Expériences>, <Category: Expériences>, <Category: Formation>, <Category: Formation>]
But it returns me too many parents !
If you could give me some advice ?
Thank you
A sample of my code if you want : http://pastebin.com/JrawK388


