如何在许多领域提供条件?

时间:2018-12-27 04:34:23

标签: python django django-models manytomanyfield

我有一个django管理页面,可以在其中添加服务并映射3种类型的实验室(专业,创新和合作伙伴)。

然后,我创建实验室,在此输入实验室类型并在创建时选择服务。

我不知道要创建一个Professional实验室的情况,只有在选择了Professional Lab中映射的服务后才应该创建实验室。

我在下面添加了模型代码和快照。

实验室创建页面和服务创建页面,我们有一个保存按钮,此处未显示 Lab creation page, we have a save button which is not seen here

[Service creation page[2]

使用此功能创建服务

class Service(models.Model):

name = models.CharField(max_length=50)
fullname = models.CharField(max_length=100)
cloud = models.CharField(max_length=10, default='aws')

__Here the services are mapped to labs using check-boxes__
in_professional = models.BooleanField(default=False)
in_innovation = models.BooleanField(default=False)
in_partner = models.BooleanField(default=False)

def save(self, *args, **kwargs):
    self.name = self.name.lower()
    self.fullname = self.fullname.title()
    self.cloud = self.cloud.lower()
    super(Service, self).save(*args, **kwargs)

def __str__(self):
    return self.name

使用此功能创建实验室

实验室类(models.Model):

class Meta:
    unique_together = (('name', 'cloud'),)
name = models.CharField(max_length=100)

__The input for lab type is given here__
type = models.CharField(max_length=100, default='professional')   # 'professional' | 'innovation' | 'partner'
cloud = models.CharField(max_length=25, default='aws')
budget_allocated = models.IntegerField(default=1)
budget_spent = models.IntegerField(default=0)
configuration = JSONField(default=None, null=True)
status = models.CharField(max_length=200, default="Inactive")
users = models.ManyToManyField(User)

__services are selected using manytomanyfeild here__
services = models.ManyToManyField(Service)

toolkits = models.ManyToManyField(Toolkit)

def __str__(self):
    return self.name

0 个答案:

没有答案