Monday, January 23, 2017

Issue with Tutorial pt 5 "Fixing the bug"

Hello all,
I am working through the Django tutorial. I've made it to "Fixing the bug" within part 5, but am having issues. The tutorial shows the following lines:
def was_published_recently(self):      now = timezone.now()      return now - datetime.timedelta(days=1) <= self.pub_date <= now
to be placed in polls/models.py.

I have made these changes and re-run the test:
$ python manage.py test polls
 Which throws:
Creating test database for alias 'default'...
SystemCheckError: System check identified some issues:

ERRORS:
<class 'polls.admin.QuestionAdmin'>: (admin.E108) The value of 'list_display[2]' refers to 'was_published_recently', which is not a callable, an attribute of 'QuestionAdmin', or an attribute or method on 'polls.Question'.

System check identified 1 issue (0 silenced).
I have gone into admin.py, but have been unable to spot the error. My admin.py looks like:
from django.contrib import admin

from .models import Question, Choice

class ChoiceInline(admin.TabularInline):
    model = Choice
    extra = 3

class QuestionAdmin(admin.ModelAdmin):
    fieldsets = [
        (None,               {'fields': ['question_text']}),
        ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
    ]
    inlines = [ChoiceInline]
class QuestionAdmin(admin.ModelAdmin):
list_display = ('question_text', 'pub_date', 'was_published_recently')
list_filter = ['pub_date']
search_fields = ['question_text']

admin.site.register(Question, QuestionAdmin)
admin.site.register(Choice)

Does anyone have any recommendations as to what my issue might be?
Thanks,
John

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8aed9aa9-c22d-4a61-b26c-649836703423%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment