我在“rlist”中列出药物清单
rlist = []
#dName = disease name and r = resulted disease
rlist.append(Disease.objects.filter(dName = r).values_list('medicine',flat=True))
通过运行此语句,我有标签管理员“医药”的ID
rlist = [<QuerySet [7]>, <QuerySet [27, 28, 29, 30]>]
但是,我想要药物的名称而不是id。
我怎么能得到???
models.py
class TaggedMedicine(TaggedItemBase):
content_object = models.ForeignKey("Disease")
def __str__(self):
return self.name
class Disease(models.Model):
did = models.AutoField(verbose_name='Disease Id', primary_key=True,auto_created=True)
dName = models.CharField(max_length=100,unique=True)
symptoms = TaggableManager(verbose_name='symptoms list', through=TaggedSymptoms) #tags with comma or space separated values
symptoms.rel.related_name = "+"
medicine = TaggableManager(verbose_name='medicine list',through=TaggedMedicine)
medicine.rel.related_name = "+"
答案 0 :(得分:2)
这只是一种表现形式。但是,如果要更改该表示形式,请在models.py中,对于Medicine类,重写__str__
方法。
def __str__(self):
return self.name #if you have a name attribute for it