List Info

Thread: generic views




generic views
user name
2007-10-22 11:40:55
Hello,

First question:

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_context9;: {'list': Event.objects.filter(date__year=????)}
}

urlpatterns = patterns('django.views.generic.simple ',
&nbsp; &nbsp;  url(r'^events/(?P<year>;d)/$9;, 'direct_to_template', e),
)
---------------------

Second question:

The url " example.com/app/events/" should be redirect to "example.com/app/events/2007/&quot;.
But 2007 shouldn9;t be hard-coded. 2007 should be the result from a object-filtering. Is this possible
with a generic view:
---------------------
urlpatterns = patterns(&#39;django.views.generic.simple&#39;,
   ;  url(r'^events/$&#39;, 'redirect_to', {'url&#39;: ???? }),
)
---------------------

Regards
&nbsp; Bernd

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

Re: generic views
country flaguser name
United States
2007-10-22 14:12:30
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-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: generic views
country flaguser name
United States
2007-10-22 14:29:40

On Mon, 2007-10-22 at 14:12 -0500, jake elliott wrote:
> 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)

by the way here's a great txt by james bennett about doing
this kind of
wrapping:

http://www.b-list.org/weblog/200
6/nov/16/django-tips-get-most-out-generic-views/

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-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )