来自其他模型列表的django用户模型

时间:2018-12-20 15:03:32

标签: python django-models

我有一个类似这样的设备的基本模型:

class device(models.Model):
    brand = models.CharField(max_length=200, blank=False)
    name = models.CharField(max_length=200, blank=False)
    available = models.BooleanField(default=False)

,我想为每个可用设备的每个用户创建一个模型条目:

class userDevice(models.Model):
    user = models.ForeignKey(User,related_name='userdevices')
    #create an entry for each device which field 'available' is true
    #add an extra boolean field 'activate' for each entry above

0 个答案:

没有答案