我基本上使用下面给出的模型制作一个django形式:
class DeviceType(models.Model):
device_type = models.CharField(max_length=200,unique=True)
class Device(models.Model):
device_type = models.ForeignKey(DeviceType,to_field='device_type')
serial_number = models.CharField(max_length=200,unique=True)
in_use_by = models.ForeignKey(User,to_field='username')
brand = models.CharField(max_length=200,default="-", null=False)
model = models.CharField(max_length=200,default="-", null=False)
type_number = models.CharField(max_length=200,blank=True,null=True)
mac_address = models.CharField(max_length=200,blank=True,null=True)
class Repair(models.Model):
device_type = models.ForeignKey(DeviceType,to_field='device_type')
submitted_by = models.ForeignKey(User,to_field='username')
comments = models.TextField()
repair_request_date = models.DateField(default=datetime.now)
repair_status = models.ForeignKey(RepairStatus, to_field="repair_status", null=True)
repair_cost_estimate = models.FloatField(null=True)
我的devicetype选项包含以下值:
Dongle Charger
Desktop Power Cord
Laptop Charger
Dongle
Keyboard
Mouse
Desktop
Laptop
现在,假设某个特定用户只拥有笔记本电脑和鼠标。如果他在我的主窗体中单击修复设备选项,则根据模型,窗体将在下拉列表中显示设备类型的所有值。我想要的是,下拉列表必须只显示笔记本电脑和鼠标,即只显示与特定用户相关的那些设备类型。我怎样才能实现这一目标?最早请求帮助。