Hi,

Sorry to bring this question up again, since it passed over this list
earlier today.
I thought that Malcolm Tredinnick post on extending generic views is
very insightful
http://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-generic-views/
as simple as that actually is. Using views.py & generic views seems
very efficient.

What I'd like to do is to add links to a page that allow a page items
to be sorted in different manners. A very common pattern obviously. I
would like to extend Malcoms snippet to complement this sorting issue,
but I'm not yet knowledgeable in Django to do this in a very efficient
manner. I'm working with the following code -thanks Malcolm-:


def event_index(request):
    if request.user.is_anonymous():
        qs = Event.objects.filter(IsInternal=True).filter(
                                        IsPublished=True
                                            ).order_by(
                                            'eventEnd'
                                        )
    else:
        qs = Event.objects.order_by('eventEnd')
    return object_list(request, qs)


let's say that I'd like to have the items on this view sorted by
'eventName', 'eventLocation', 'eventStart',  and to filter out any
events where 'isEventPassed' is true for example. Coding each of these
views doesnt seem a very DRY thing to do here, since I'm just sorting
the data differently...

So in a way one would think a functional approach would make sense
here, something like:

def event_sorted(request, attribute):
    if request.user.is_anonymous():
        qs = Event.objects.filter(IsInternal=True).filter(
                                        IsPublished=True
                                            ).order_by(
                                            'attribute'
                                        )
    else:
        qs = Event.objects.order_by('attribute')
    return object_list(request, qs)

I'd love to hear what would be a succinct way of coding such views!

Cheers!

-jelle


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to