Hi,

There are defaults that are used for things like template_name. You should
strive to follow the templates, then you don't need to write that much code.

Check out the documentation for ListView:
https://docs.djangoproject.com/en/dev/topics/class-based-views/generic-display/#generic-views-of-objects

You can also read what the get_queryset function is for.

Regards,

Andréas

2018-01-25 12:31 GMT+01:00 Mukul Agrawal <amuku...@gmail.com>:

> I have two snap of code below.  I want to know that in the first one I
> used template_name='restaurants/restaurants_list.html' which is obvious
> if I want to use a template but in the second one I have not specified the
> template name even then it shows the correct web page.How?
>
>
>
>
> class RestaurantListView(ListView):
> template_name='restaurants/restaurants_list.html'
> def get_queryset(self):
> slug=self.kwargs.get("slug")
> if slug:
> queryset=RestaurantLocation.objects.filter(
> Q(category__iexact=slug)|
> Q(category__icontains=slug)
> )
> else:
> queryset=RestaurantLocation.objects.all()
> return queryset
>
> ##########################################################
>
> class RestaurantListView(ListView):
> def get_queryset(self):
> return RestaurantLocation.objects.all(owner=self.request.user)
>
>
>
>
> --
> 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+unsubscr...@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/c29ef43a-ff1e-4008-a2c9-099bf226d5df%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c29ef43a-ff1e-4008-a2c9-099bf226d5df%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CAK4qSCff1Qm0UAmeHh17B1qK-s9sx4sTqxN1YaaBxUtDxbkdSw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to