I have Django models that are lists of items and I want the items on each list to have a separate sort order. Maybe list 1 will sort line items by name, list 2 by date, and list 3 by priority.
The models looks more or less like this:
class ListItem(models.Model):
priority = models.IntegerField(choices=PRIORITY_CHOICES)
name = models.CharField(max_length=240)
due_date = models.DateTimeField(null=True, blank=True)
list = models.ForeignKey(List)
Right now I'm using this query in my view:
lists = List.objects.filter(user=request.user)
return render_to_response('showlists.html', {'lists': lists })
I've read examples that imply that I could do something like this:
lists = List.objects.filter(user=request.user).select_related().order_by("items.name")
Assuming that worked, it would give me the collection of lists with an identical sort order for each batch of items. How would I go about sorting each individual list's related items differently?