自定义权限无法在权限表中显示

时间:2016-07-12 02:41:46

标签: django

我尝试在员工模型中创建一个查看权限。但是,它在默认权限表中不存在。表中仍存在默认权限,例如“添加”,“更改”,“删除”。我需要再次迁移吗?谁能给我一个提示?

class Staff(AbstractBaseUser):

  yes_or_no = ((True, 'Yes'),(False, 'No'))
  male_or_female = ((True,'Male'),(False,'Female'))

  name = models.CharField(max_length=100,blank = False, null = False)
  email = models.EmailField(max_length=100,blank = False, null = False)
  gender = models.BooleanField(default = True, choices = male_or_female)
  birthday = models.DateField(default =None,blank = False, null = False)
  created = models.DateTimeField(default=datetime.now, blank=True)
  is_staff = models.BooleanField(default=False,choices = yes_or_no) 
  store_id = models.ForeignKey(Store,default=1) 
  REQUIRED_FIELDS = ['email']

  permissions = (
            ("view_Staff", "Can see available Staff"))

  perm_list = set()
  def get_user_type(self):
    return "Staff"

  def has_perm(self, perm, obj=None):
    if perm in self.get_all_permissions():
      return True
    return False

  def get_all_permissions(self, obj=None):
        return self.perm_list

  def asgin_perm(self,perm,object=None):
    self.perm_list.add(perm)

  def __str__(self):
    return self.name

1 个答案:

答案 0 :(得分:0)

您是否应该像这样在元类中设置自定义权限...

class Meta:
    permissions = (
        ("view_staff", "Can see available staff"),
    )