hi bernd,
On Mon, 2007-10-22 at 18:40 +0200, Bernd wrote:
> I want to use a generic view with an url that had a
parameter. This
> parameter should filter my queryset.
> How does this work? I don't now what to write in the
filter-option?
> ---------------------
> e = {
> 'template': 'foo.html',
> 'extra_context': {'list':
Event.objects.filter(date__year=????)}
> }
>
> urlpatterns = patterns('django.views.generic.simple ',
> url(r'^events/(?P<year>d)/$',
'direct_to_template', e),
> )
> ---------------------
you may run into some trouble here constructing that query
in urls.py.
but really the view that you're composing here is pretty
simple without
generic views:
# views.py
def myview(request, year):
return render_to_response('foo.html',
{ 'list': Event.objects.filter(date__year=year) })
> The url "example.com/app/events/" should be
redirect to
> "example.com/app/events/2007/".
> But 2007 shouldn't be hard-coded. 2007 should be the
result from a
> object-filtering. Is this possible
> with a generic view:
> ---------------------
> urlpatterns = patterns('django.views.generic.simple',
> url(r'^events/$', 'redirect_to', {'url': ???? }),
> )
> ---------------------
this is probably another really simple view. you can use
HttpResponseRedirect - or if you really want to end up using
a generic
view remember that you can call them within your own views
also.
# views.py
from django.views.generic.simple import redirect_to
def myview(request):
# something
return redirect_to(url=mycalculatedurl)
best
jake
--~--~---------~--~----~------------~-------~--~----~
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 htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|