Django-CheckboxSelectMultiple显示对象表示形式而不是对象名称 [英] Django - CheckboxSelectMultiple shows object representation instead of object's name
本文介绍了Django-CheckboxSelectMultiple显示对象表示形式而不是对象名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我尝试列出城市的复选框,但未显示城市名称,而是显示以下内容:
So I am trying to have a list of checkboxes of cities, but instead of showing the cities' name, it shows this:
如何显示名称而不是城市对象
?
推荐答案
在模型中,您必须为python3包括 __ str __ ,为python 2包括 unicode
In your model you have to include __str__ for python3 and unicode for python 2
例如python 3:
For example python 3:
class City(models.Model):
name = forms.CharField(max_length=200, default="")
def __str__(self):
return self.name
Python 2
class City(models.Model):
name = forms.CharField(max_length=200, default="")
def __unicode__(self):
return self.name
这篇关于Django-CheckboxSelectMultiple显示对象表示形式而不是对象名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文