我正在尝试建立一个频道。我不希望其他用户有权访问详细视图。问题是我可以让一个人可以访问它,但我不知道如何让消费者和卖家都可以访问它?
class Group(models.Model):
consumer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="", blank=True, null=True)
name = models.CharField(max_length=10)
seller = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="")
...
def __str__(self):
return self.name
#Detail channel
@method_decorator(login_required(login_url='/cooker/login'),name="dispatch")
class CheckoutDetail(generic.DetailView):
...
def get(self,request,*args,**kwargs):
self.object = self.get_object()
if self.object.consumer or self.object.seller != request.user: #it's redirect me to home page
return HttpResponseRedirect('/')
return super(CheckoutDetail, self).get(request,*args,**kwargs)
FFIVE
哈士奇WWW
相关分类