Friday, February 24, 2017

Benefit of 'return Foo.objects.all()' in a ListView

Hi there,

I'm starting to learn about Django views and wanted to ground my understanding.

What is the advantage of including the get_queryset(self) function in a ListView? When I've run it with a very basic model ('Foo') there doesn't appear to be any difference with/without it - this could well be that my examples are currently too basic.

Essentially, what is the difference between the two below:

# view.py
from .models import Foo
from django.views.generic import ListView


class IndexView(ListView):
    model = Foo

    def get_queryset(self):
        return Foo.objects.all()

vs

# view.py
from .models import Foo
from django.views.generic import ListView


class IndexView(ListView):
    model = Foo

Thanks!

Rich

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9c11d894-1a08-4b24-b769-682c47a0a436%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment