我想仅使用django admin在我的网站上提供PDF文档。我完全迷失了这就是我的模特
class Examination(models.Model):
examination_name = models.CharField(max_length=50)
class Meta:
verbose_name='examination'
verbose_name_plural='examinations'
def __unicode__(self):
return self.examination_name
# Create your models here.
class Year(models.Model):
examinations = models.ForeignKey('Examination')
examination_year = models.CharField(max_length=4)
class Meta:
verbose_name='year'
verbose_name_plural='years'
def __unicode__(self):
return self.examination_year
class PastQuestion(models.Model):
years = models.ForeignKey(Year)
file = models.FileField(upload_to='uploads/', max_length=100,)
posted_by = models.CharField(max_length=50)
def __unicode__(self):
return self.years
然后当我尝试从管理界面打开PastQuestion时出现此错误。 / admin / PastQuestion / pastquestion /
中的TypeError强制转换为Unicode:需要字符串或缓冲区,Year如何正确执行此操作
这是我点击PastQuestion时得到的错误
/ admin / PastQuestion / pastquestion /
中的TypeError强制转换为Unicode:需要字符串或缓冲区,找到年份
请求方法:GET 请求网址:http://127.0.0.1:8000/admin/PastQuestion/pastquestion/ Django版本:1.10 异常类型:TypeError 例外值:
强制转换为Unicode:需要字符串或缓冲区,找到年份
异常位置:/home/tomms/Desktop/project/local/lib/python2.7/site-packages/django/utils/encoding.py in force_text,第78行 Python可执行文件:/ home / tomms / Desktop / project / bin / python Python版本:2.7.9 Python路径:
[ '/家/ tomms /桌面/项目/源', '/home/tomms/Desktop/project/lib/python2.7', '/home/tomms/Desktop/project/lib/python2.7/plat-x86_64-linux-gnu', '/home/tomms/Desktop/project/lib/python2.7/lib-tk', '/home/tomms/Desktop/project/lib/python2.7/lib-old', '/home/tomms/Desktop/project/lib/python2.7/lib-dynload', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/home/tomms/Desktop/project/local/lib/python2.7/site-packages', '/home/tomms/Desktop/project/lib/python2.7/site-packages']
服务器时间:2017年8月23日星期三01:54:37 +0000 模板渲染期间出错
在模板/home/tomms/Desktop/project/local/lib/python2.7/site-packages/django/contrib/admin/templates/admin/change_list.html中,第82行出错