我是否需要为公司的休假审批人建立多对多的关系?

时间:2017-12-18 11:45:05

标签: django django-models

我有:UserCompany

class User(AbstractBaseUser):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    company = models.ForeignKey(
        'projects.Company',
        on_delete=models.PROTECT
    )


class Company(models.Model):
    '''Company model
    every user needs to be assigned to a company
    '''
    name = models.CharField(max_length=255, unique=True)

现在我需要设置一个leave approverscompanyUsersLeaveApprover。可能会有一些,我想为他们设置优先级。

如果它是单个Company,那么我只需使用LeaveApprover的外键向many-to-many模型添加一对一。但就我而言,公司可以拥有多个审批人,审批人只能批准一家公司。

我需要[ req ] default_bits = 2048 distinguished_name = req_distinguished_name req_extensions = req_ext [ req_distinguished_name ] countryName = Country Name (2 letter code) stateOrProvinceName = State or Province Name (full name) localityName = Locality Name (eg, city) organizationName = Organization Name (eg, company) commonName = Common Name (e.g. server FQDN or YOUR name) [ req_ext ] subjectAltName = @alt_names [ alt_names ] DNS.1 = localhost IP.1 = 127.0.0.1 字段吗?

1 个答案:

答案 0 :(得分:1)

我认为在User模型中添加指定字段会起作用。 您可以根据指定轻松过滤用户;如果他是雇员或批准者,它将区分。 模型看起来像这样......

class User(AbstractBaseUser):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    role = models.CharField(max_length=15)
    company = models.ForeignKey(
        'projects.Company',
        on_delete=models.PROTECT
    )


class Company(models.Model):
    '''Company model
    every user needs to be assigned to a company
    '''
    name = models.CharField(max_length=255, unique=True)

现在公司可以拥有多个审批人,审批人只能批准一家公司。

在您的视图中,您可以编写逻辑或根据角色分配特定权限。