Sunday, November 1, 2020

django-filter according to logged user

Hi,

I am using the django_filters to filtering the information. However, it is showing the data of all logged user of my systems. I need show only the data of logged user. 

Follow the files:

filters.py 

import django_filters
from apps.requisitos.models import Requisito

class RequisitoFilter(django_filters.FilterSet):
class Meta:
model = Requisito
fields = ['nomeRequisito', 'projeto']

views.py

class RequisitoList(ListView):
paginate_by = 10
model = Requisito

def get_queryset(self):
usuarioLogado = self.request.user
return Requisito.objects.filter(user=usuarioLogado)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['filter'] = RequisitoFilter(self.request.GET, queryset=self.queryset)
return context

the loop for of html page

{% for requisito in filter.qs %}

thank you very much

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3f44722b-5b44-4fab-9d5b-26bc3a648ae7n%40googlegroups.com.

No comments:

Post a Comment