我正在尝试编写一个函数来检查用户是否具有正确的成员类别。
我的模型:
from django.db import models
from django.contrib.auth.models import User
class Membercategory(models.Model):
membercatname = models.CharField(max_length=200)
class Profile(models.Model):
user = models.OneToOneField(User)
mobilephone = models.CharField(max_length=12, blank=True)
membercategory = models.ForeignKey(Membercategory, blank=True, null=True)
我的用户检查中间件:
from django.http import HttpResponseRedirect
from django.conf import settings
class UserCheckMiddleware:
def process_request(self, request):
invalid_user_path = settings.INVALID_USER_URL
if request.user.is_authenticated() and not request.user.is_staff:
if not request.user.profile.membercategory(id=426):
return HttpResponseRedirect(invalid_user_path)
else:
return
我得到的错误是:Membercategory object is not callable
我应该怎么做检查?