A little background about our specific problem ->
We are trying to build a Q & A site, much like Stackoverflow.
People can come and ask questions and other people reply.
So like SO (https://stackoverflow.com/questions) we have a questions page. Now the problem we’re having is that we have this model :
class Questions(models.Models):
user = person
question = CharField
number_of_replies = IntegerField
datetime = DateTime
The resultant queryset ( or list ) is determined by a combination of various factors like when it was posted, how many people replied to it, etc.
Since there’s been confusion related to the question i’ll clarify it ->
This is the kind of output I’m looking for :
This is how the final order will be ->
- Question c posted 10 mins ago, 0 replies
- Question f posted 1 min ago, 2 replies
- Question b posted 5 mins ago, 1 reply
etc.
so there is no one-dimensional order, the order is a function of various parameters
One way of doing it is by defining a custom manager ->
https://docs.djangoproject.com/en/dev/topics/db/managers/#custom-managers-and-model-inheritance.
You can display the objects in any order you like. You can even return lists and self-defined dictionaries using the custom manager methods.