Sunday, June 3, 2012

Re: SOLVED Django 1.3 Ordering by two or more fields workaround ??

Solved working on admin instead of models, in the following way

------------- admin.py----------------------------------
class SpecialOrderingChangeList(ChangeList):
'''
Django 1.3 ordering problem workaround
from 1.4 it's enough using ordering var
'''
def get_query_set(self):
queryset = super(SpecialOrderingChangeList, self).get_query_set()
return queryset.order_by(*self.model._meta.ordering)

class CollectionAdmin(admin.ModelAdmin):
list_display = ('collection_prdct','ordr', 'product')

def get_changelist(self, request, **kwargs):
return SpecialOrderingChangeList
end ------------- admin.py----------------------------------

Now the list_display of admin is ordered by all the fields in
meta.ordering not only by the first


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment