У меня проблема с UserPassesTestMixin, я хочу ограничить просмотры от просмотра людей, назначенных для менеджера. Это дает мне ошибку: у объекта 'teamview' нет атрибута 'get_object'.
Вот мой views.py в вопросе:
from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import ListView, CreateView, DetailView
from .models import Job, Member
from profiles.models import User
from django.contrib.auth.decorators import login_required
# Create your views here.
class jobs(LoginRequiredMixin,ListView):
model = Job
template_name = 'users/user_jobs.html'
context_object_name = 'jobs'
def get_queryset(self):
return Job.objects.filter(member__member=self.request.user)
class createdjobs(LoginRequiredMixin,ListView):
model = Job
template_name = 'users/manager_jobs.html'
context_object_name = 'jobs'
def get_queryset(self):
return Job.objects.filter(manager__manager=self.request.user)
class teamview(LoginRequiredMixin,UserPassesTestMixin,ListView):
model = Member
template_name = 'users/manage_team.html'
context_object_name = 'members'
def test_func(self):
return self.get_object().manager == self.request.user
def get_queryset(self):
return Member.objects.filter(manager__manager=self.request.user)
class jobdetail(LoginRequiredMixin,DetailView):
model = Job
class createjob (LoginRequiredMixin,UserPassesTestMixin,CreateView):
model = Job
fields = ['member','title', 'description', 'file']
def form_valid(self,form):
form.instance.manager=manager.objects.get(manager=self.request.user)
return super().form_valid(form)
def test_func(self):
return self.get_object().manager == self.request.user
Надеюсь, вы не можете помочь мне с этим TIA .