> A queryset returns a /list/ of model instances. Thus you should queryset
> when you want more then one instance of the model displayed.

well, slightly wrong, let's clarify. While it's true a queryset
represents a list of model instances (it's not EXACTLY that, it's,
more like, a partially set up query that only gets ran when you
actually request the objects), in GenericViews the difference between
setting up a model and a queryset is that setting up model=Post is the
same as setting up queryset=Post.objects.all(). So if you want your
view to act upon ALL Post instances, and you don't care about
ordering, then you can do model=Post and save yourself some typing.

If, however, you want your view to act upon only a SUBSET of objects,
you can use queryset. If, for example, you are making a list of books
made by a specific author, you can do this:

url(r'^books/shakespeare/$',
ListView.as_view(queryset=Book.objects.filter(author='shakespeare')),...

(of course, this isn't the best example, since it'd be much smarter to
make a more specific view that filters authors by a parameter,
something like (r'books/(P<author_slug>\w+)/$')), but it serves as
example)

In the docs' example, the queryset= parameter is used, because they
want the view to show only the latest 5 Polls, hence the
queryset=Poll.objects.order_by('-pub_date')[:5]. If you wanted ALL,
but ordered by -pub_date (and this wasn't the default ordering for the
model), you would use the same queryset, but leaving out the [:5]
part.

-- 
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to