2017-09-14 29 views
-2

我有一个领域是自定义标签。使用Django taggit输出的是标记insted name的标识。如何将输出更改为标记名称?

当我从模型中获得该特定字段并尝试打印该字段中的所有存储值时,它将显示为每个值的Id。

我怎样才能得到我存储为字符串的值。

  • views.py

    def patfirst(request): 
    if request.method == "GET": 
        return render(request, 'personal/patfirst.html') 
    
    if request.POST.get('Next'): 
        newSymp = request.POST.get('newSymptom') 
        didata = Disease.objects.all().values_list('symptoms') 
        args = {'newSymp' : newSymp,'didata':didata} 
        return render(request, 'personal/patfirst.html',args) 
    
  • models.py

    class TaggedSymptoms(TaggedItemBase): 
        content_object = models.ForeignKey("Disease") 
    
    class Disease(models.Model): 
        did = models.AutoField(verbose_name='Disease Id', primary_key=True,default=0) 
        dName = models.CharField(max_length=100) 
    
        symptoms = TaggableManager(verbose_name='symptoms list', through=TaggedSymptoms)     
        symptoms.rel.related_name = "+" 
    
  • patfirst.html

    <h1>search disease</h1> 
        <form method="post" action="#"> 
        {% csrf_token %} 
        Enter Symptom: <input type="text" name="newSymptom"/><br><br> 
        <h3> 
         {% for s in didata %} 
          {{ s }} 
         {% endfor %} 
        </h3> 
        <input type="submit" value="Next" name="Next"/> 
        <input type="submit" value="None of these" name="NoneOfThese"/> 
        </form> 
    

output I got is like this:

+2

码?输入?预期的产出? – schwobaseggl

+0

输入:任何症状。例如:发烧和输出:所有症状列表将被采取,其疾病包含发热症状。例如:登革热的症状包括(发烧,头痛,关节痛)和流感(发烧,肌肉酸痛,头痛)。因此,登革热和流感将显示为输出。 –

回答

0

没有你提供太多细节,我可以猜测,你可以通过打印这种方式这样做。(提供,以便更多的信息,获得更精确的答案)

tags = your_object.tags 
for tag in tags: 
    print tag, tag.your_string_field 
+0

我有多个tags.So,因为它是这个方法保持不变? –