答案 0 :(得分:1)
最简单的方法是在InputStream is = getContentResolver().openInputStream(data.getData());
模型类中实现__str__
方法,如下所示:
Line
请注意,这将更改整个网站上的线对象名称,而不仅仅是class Line(models.Model):
# Yourcode
def __str__(self):
return "Some text" # you can use any Line's field her e.g return self.name
答案 1 :(得分:1)
对于Python3
class Line(models.Model):
# Your others model field Declaration
field1 = models.CharField("Model Field", unique=True, max_length=128, blank=True, null=True)
def __str__(self):
return self.field1
# or return "Any text that you want to show as model name"
在旧版本的Django和Python2中,您经常会看到以下功能。
class Line(models.Model):
# Your others model field Declaration
field1 = models.CharField("Model Field", unique=True, max_length=128, blank=True, null=True)
def __unicode__(self):
return self.field1
# or return "Any text that you want to show as model name"
以下代码将在整个项目中充当模型名称。