Home > other >  Django UpdateView can edit user who created and user to whom record is assigned
Django UpdateView can edit user who created and user to whom record is assigned

Time:06-09

Let's say I have model like

class Record(models.Model):
  created = ......
  assigned = .......
  some_other_fields = .....

How should I modify test_func() in views to allow edit Record both to creator and user to whom the Record is assigned? I would like to enable functionality in frontend side, not in the django admin panel. I'm working with Class Based Views.

Standard test_func in UpdateView looks like:

def test_func(self):
  return self.request.user == self.object.created

Thanks a lot!

CodePudding user response:

is this what you need?

def test_func(self):
  return self.request.user == self.object.created == self.object.assigned

or

def test_func(self):
     if self.request.user == self.object.created:
         if self.request.user == self.object.assigned:
             return True
      return False

CodePudding user response:

My code, based on @enes-islam answer:

def test_func(self):
     if self.request.user == self.object.created or self.request.user == self.object.assigned:
             return True
      return False
  • Related