0

I want to serve PDF document on my website using the django admin only. I am totally lost this is what i have as my model

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

Then I get this error when i try to open PastQuestion from my admin interface. TypeError at /admin/PastQuestion/pastquestion/

coercing to Unicode: need string or buffer, Year found how do I do this properly

This is the error I got when i click on PastQuestion

TypeError at /admin/PastQuestion/pastquestion/

coercing to Unicode: need string or buffer, Year found

Request Method: GET Request URL: http://127.0.0.1:8000/admin/PastQuestion/pastquestion/ Django Version: 1.10 Exception Type: TypeError Exception Value:

coercing to Unicode: need string or buffer, Year found

Exception Location: /home/tomms/Desktop/project/local/lib/python2.7/site-packages/django/utils/encoding.py in force_text, line 78 Python Executable: /home/tomms/Desktop/project/bin/python Python Version: 2.7.9 Python Path:

['/home/tomms/Desktop/project/source', '/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']

Server time: Wed, 23 Aug 2017 01:54:37 +0000 Error during template rendering

In template /home/tomms/Desktop/project/local/lib/python2.7/site-packages/django/contrib/admin/templates/admin/change_list.html, error at line 82

0 Answers0