Well, as the error says, Django model instances are not callable. You just want a simple comparison to the ID:
if request.user.profile.membercategory_id != 426:
Pergunta
Im trying to write a function to check that the user has correct member category.
My models:
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)
My user-check middleware:
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
The error I get is: Membercategory object is not callable
How should I do the check?
Solução
Well, as the error says, Django model instances are not callable. You just want a simple comparison to the ID:
if request.user.profile.membercategory_id != 426: