Where to control permission-style viewing in Django? In the url (via generic views), template, or view?
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Flying Over Ancient Lands
--
Chapters
00:00 Question
02:29 Accepted answer (Score 2)
02:48 Thank you
--
Full question
https://stackoverflow.com/questions/1006...
Question links:
[get_context_data]: https://docs.djangoproject.com/en/dev/to...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #permissions #djangotemplates #djangoviews
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Flying Over Ancient Lands
--
Chapters
00:00 Question
02:29 Accepted answer (Score 2)
02:48 Thank you
--
Full question
https://stackoverflow.com/questions/1006...
Question links:
[get_context_data]: https://docs.djangoproject.com/en/dev/to...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #permissions #djangotemplates #djangoviews
#avk47
ACCEPTED ANSWER
Score 2
If you use ListView there is get_queryset() method to do this:
class OrderListView(ListView):
template_name = 'doors/orders/list.html'
def get_queryset(self):
user = self.request.user
if user.user_type == 1:
return Order.objects.all()
return Order.objects.filter(creator=user.pk)