On Saturday 25 February 2006 16:58, ChaosKCW wrote:
> Please can someone help. I am following Tutorial4 for
generic views,
> plus adapting it to the magic removal instructions on
the wiki page.
> As far as I can tell i followed the instructions
exactly, But I get
> an error stating that 'model' is not a valid
paremeter to the view.
The tutorial is now badly out of date for magic-removal.
Instead of
taking a model and app_label, they take a 'queryset'
argument, which
should be a QuerySet object. QuerySet objects are what you
implicitly
use in magic removal to do all lookups on the database. For
instance,
Poll.objects.all() is a QuerySet. Because QuerySets are
'lazy', you
can create them in your URL conf and the data won't be
retrieved at
that point, but each time the generic view is actually
called. In my
urls.py I have something like this:
(r'^sites/$', 'list_detail.object_list',
{'queryset': Site.objects.all(),
'template_name': 'cciw/sites/index'
}
),
(r'^sites/(?P<slug>.*)/$',
'list_detail.object_detail',
{'queryset': Site.objects.all(),
'slug_field': 'slug_name',
'template_name': 'cciw/sites/detail'
}
),
...
Note how I use all the 'Site' objects in the both cases,
but don't worry
-- only in the first case does it actually result in all the
objects
being retrieved from the db, in the second case the view
derives a new
QuerySet, based on the one passed in, that only gets a
single object.
I personally think the new syntax is much nicer - no need
for
'extra_lookup_args' etc. If you wanted to have a
different ordering
plus extra filtering, you could change Site.objects.all() to
e.g.
Site.objects.filter(visible=True).order_by('name').
One thing - I'm not sure all the generic views have been
updated yet. I
do know the above examples work.
Luke
--
Parenthetical remarks (however relevant) are unnecessary
Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/
--~--~---------~--~----~------------~-------~--~----~
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://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|