我有三个模型:
class Instances(models.Model):
name_of_instances = models.CharField(max_length=255)
url_of_instances=models.URLField(max_length=255,default='')
def __str__(self):
return self.name_of_instances
class Projects(models.Model):
name_of_instances = models.ForeignKey(Instances,on_delete=models.CASCADE)
name_of_jproject = models.CharField(max_length=255)
project_id= models.CharField(max_length=25)
def __str__(self):
return self.name_of_project
class All(models.Model):
choices_instance=Instances.objects.all()
b = [str(i.name_of_instances) for i in choices_instance]
a=[str(i.url_of_instances) for i in choices_instance]
choices_instance=tuple(zip(a,b))
name = models.CharField(max_length=255,choices=choices_instance)
project = models.CharField(max_length=255,)
story = models.CharField(max_length=500)
depends_on = models.CharField(max_length=500, default='')
rfc = models.CharField(max_length=255)
def __str__(self):
return self.name
我有一个模型表单:
class Form(ModelForm):
class Meta:
model = All
fields =('name','project','story','depends_on','rfc')
在模板中,我想知道' name‘字段中有哪些用户,我想将name值发送到后端函数,在那里我将过滤出与name值关联的所有项目,并将结果发送到'project’字段作为选择(下拉)。
https://stackoverflow.com/questions/47738268
复制