what does the below mentioned error means and how do i resolve this error.something is wrong with my admin.py file.Please comment:

1,943 views
Skip to first unread message

Avitab Ayan Sarmah

unread,
Jun 7, 2018, 11:08:15 AM6/7/18
to Django users
In windows powershell:

ERRORS:
<class 'polls.admin.QuestionAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'question_text', which is not a callable, an attribute of 'QuestionAdmin', or an attribute or method on 'polls.Question'.
<class 'polls.admin.QuestionAdmin'>: (admin.E108) The value of 'list_display[1]' refers to 'pub_date', which is not a callable, an attribute of 'QuestionAdmin', or an attribute or method on 'polls.Question'.
<class 'polls.admin.QuestionAdmin'>: (admin.E116) The value of 'list_filter[0]' refers to 'pub_date', which does not refer to a Field.

System check identified 3 issues (0 silenced).

polls\models.py:

import datetime

from django.db import models
from django.utils import timezone


class Question(models.Model):
    #...
    def was_published_recently(self):
        now = timezone.now()
        return now - datetime.timedelta(days=1) <= self.pub_date <= now
    was_published_recently.admin_order_field = 'pub_date'
    was_published_recently.boolean = True
    was_published_recently.short_description = 'published recently?'
class Choice(models.Model):
    #...
    def __str__(self):
        return self.choice_text
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)


polls\admin.py:


from django.contrib import admin

from . models import Choice, Question


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]
    list_display = ('question_text', 'pub_date', 'was_published_recently')
    list_filter = ['pub_date']

admin.site.register(Question, QuestionAdmin)


Mario R. Osorio

unread,
Jun 8, 2018, 9:52:30 AM6/8/18
to Django users
Looks like you skiped a huge part of the tutorial. you might to go back...

Avitab Ayan Sarmah

unread,
Jun 8, 2018, 9:57:33 AM6/8/18
to django...@googlegroups.com
Can you tell me what is wrong in my admin.py file because from exception it seems that list_display() is having something wrong which I am not able to find out

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/444q_hv6-aA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@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/8c65b7f0-9ca7-4e07-8167-fb29274710e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony Flury

unread,
Jun 8, 2018, 2:39:39 PM6/8/18
to Avitab Ayan Sarmah, django...@googlegroups.com
The errors are relatively obvious to be frank - see the responses below ...


On 08/06/18 14:56, Avitab Ayan Sarmah wrote:
> Can you tell me what is wrong in my admin.py file because from
> exception it seems that list_display() is having something wrong which
> I am not able to find out
>
> On Fri 8 Jun, 2018, 7:23 PM Mario R. Osorio, <nimbi...@gmail.com
> <mailto:nimbi...@gmail.com>> wrote:
>
> Looks like you skiped a huge part of the tutorial. you might to go
> back...
>
> On Thursday, June 7, 2018 at 11:08:15 AM UTC-4, Avitab Ayan Sarmah
> wrote:
>
> In windows powershell:
>
> ERRORS:
> <class 'polls.admin.QuestionAdmin'>: (admin.E108) The value of
> 'list_display[0]' refers to 'question_text', which is not a
> callable, an attribute of 'QuestionAdmin', or an attribute or
> method on 'polls.Question'.
>

In your list_display field (on your QuestionAdmin)  refers to a field
'question_text' which doesn't exist on either the QuestionAdmin or the
Question model; i.e. that field does not exist in either model.

> <class 'polls.admin.QuestionAdmin'>: (admin.E108) The value of
> 'list_display[1]' refers to 'pub_date', which is not a
> callable, an attribute of 'QuestionAdmin', or an attribute or
> method on 'polls.Question'.
>
In your list_display field (on your QuestionAdmin)  refers to a field
'pub_date' which doesn't exist on either the QuestionAdmin or the
Question model; i.e. that field does not exist in either model.
>
> <class 'polls.admin.QuestionAdmin'>: (admin.E116) The value of
> 'list_filter[0]' refers to 'pub_date', which does not refer to
> a Field.
>
In your list_filter field (on your QuestionAdmin)  refers to a field
'pub_date' which doesn't exist on either the QuestionAdmin or the
Question model; i.e. that field does not exist in either model.

To be honest the error message you got says exactly what the problem is
- the fields that you think exist don't exist. You need to check your
models, and check the field names, spellings etc.

>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/444q_hv6-aA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email
> to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> <https://groups.google.com/d/msgid/django-users/8c65b7f0-9ca7-4e07-8167-fb29274710e1%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@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/CAEx5wm7JH77g9JfU%3DzHY3%2BCiDbnD3vDnaXLy%3DV1mE8E2wCrd2g%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAEx5wm7JH77g9JfU%3DzHY3%2BCiDbnD3vDnaXLy%3DV1mE8E2wCrd2g%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
--
Anthony Flury
email : *Anthon...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

Reply all
Reply to author
Forward
0 new messages