django-filter according to logged user

113 views
Skip to first unread message

Gabriel

unread,
Nov 1, 2020, 4:20:13 PM11/1/20
to Django users
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
Reply all
Reply to author
Forward
0 new messages