I have a Project model
class Project(models.Model)
name = models.CharField(max_length=255)
members = models.ManyToManyField(User, related_name="members")
and I am using a classbased Update view to restrict only those users who are members of the project.
class ProjectUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
model = Project
fields = ["name"]
def test_func(self):
members = self.get_object().members.all()
if members.contains(self.request.user):
return True
return False
After looking at the SQL queries through Djang Debug Toolbar, I see the query is duplicated 2 times.
the 1st instance is from this test_func and the other instance is from django generic views, how can I resolve the duplicated query issue