You have a Model. You want to sort its instances by a parameter. This parameter should be passed in the url. Here you go.
It is pretty much from docs, I just didn’t find it fast enough in the first time, so I decided to post about it.
Read More »You have a Model. You want to sort its instances by a parameter. This parameter should be passed in the url. Here you go.
It is pretty much from docs, I just didn’t find it fast enough in the first time, so I decided to post about it.
Read More »A small piece of code, very simple.
Read More »What can be easier? Populate a slug
field, make a get_absolute_url
, make a simple view
, add a line to urlpatterns
. Right? Well guess again.
So you are casually overriding get_queryset()
in a, say, ListView, like this:
def get_queryset(self):
entries = [x for x in Entry.objects.all() if x.publications]
return entries
Because you need to sort the Entry
table by a reverse M2M relation publications
and then BAM!:
Attribute error 'list' object has no attribute 'filter'
Without a trace of the line you made a mistake in…
Read More »