Admin options are just ignored

48 views
Skip to first unread message

somen...@gmail.com

unread,
Aug 10, 2014, 3:09:36 PM8/10/14
to django...@googlegroups.com
Hi,

I'm following the django tutorial with my application. When I add fieldset, search_fields, and other options in the admin.py in my app, django-admin ignores that.


Can anyone take a look. Thanks in advance,
Xan

Adrian Marshall

unread,
Aug 10, 2014, 6:02:34 PM8/10/14
to django...@googlegroups.com
Think I found the problem.
You're not registering the new Admin model classes you have made.

change: admin.site.register(Resguard)
to this:
            admin.site.register(Resguard,ResguardAdmin)

do the same with the rest of your admin.site.register() functions

That should work! Hope that helps!

somen...@gmail.com

unread,
Aug 11, 2014, 4:58:53 AM8/11/14
to django...@googlegroups.com
Thank you very much. You're right.
In the official documentation there is no reference of that (step 2). Can anyboydy add it?

Thanks,

El dilluns 11 d’agost de 2014 0:02:34 UTC+2, Adrian Marshall va escriure:

James Bennett

unread,
Aug 11, 2014, 5:02:36 AM8/11/14
to django...@googlegroups.com
It is there in the documentation.

The first instance just uses "admin.site.register(Poll)" because it hasn't yet begun customizing.

Once it starts explaining customization, it tells you, in that section:

https://docs.djangoproject.com/en/1.6/intro/tutorial02/#customize-the-admin-form

to change it to "admin.site.register(Poll, PollAdmin)".

somen...@gmail.com

unread,
Aug 11, 2014, 12:10:48 PM8/11/14
to django...@googlegroups.com
Mmm.. sorry. I did not see that.

One more error: after making these changes, I receive

FieldError at /admin/tasques/resguard/1/

Unknown field(s) (data_modificacio) specified for Resguard. Check fields/fieldsets/exclude attributes of class ResguardAdmin.

in http://localhost:8000/admin/tasques/resguard/1/


If I have
class ResguardAdmin(admin.ModelAdmin):
    fieldsets = [
        (None,               {'fields': ['ref', 'titol']}),
        ('Estat', {'fields': ['estat', 'resolucio', 'tipus', 'prioritat']}),
        ('Data', {'fields': ['data_creacio', 'data_resolucio']}), # falta data_modificacio
        ('Classificació', {'fields': ['etiquetes', 'component', 'fites', 'installacio']}),
        ('Descripció', {'fields': ['sintaxi_cos', 'cos']}),
        ('Referències', {'fields': ['referencies']}),
        ('Informació adjunta', {'fields': ['adjunts', 'codis']}),
    ]
    list_display = ('__str__', 'estat', 'tipus', 'prioritat', 'data_modificacio', 'component', 'edat')
    search_fields = ['titol', 'cos']

all is ok

but if I put
class ResguardAdmin(admin.ModelAdmin):
    fieldsets = [
        (None,               {'fields': ['ref', 'titol']}),
        ('Estat', {'fields': ['estat', 'resolucio', 'tipus', 'prioritat']}),
        ('Data', {'fields': ['data_creacio', 'data_resolucio', 'data_modificacio']}),
        ('Classificació', {'fields': ['etiquetes', 'component', 'fites', 'installacio']}),
        ('Descripció', {'fields': ['sintaxi_cos', 'cos']}),
        ('Referències', {'fields': ['referencies']}),
        ('Informació adjunta', {'fields': ['adjunts', 'codis']}),
    ]
    list_display = ('__str__', 'estat', 'tipus', 'prioritat', 'data_modificacio', 'component', 'edat')
    search_fields = ['titol', 'cos']

then, the error.

What's wrong?

Collin Anderson

unread,
Aug 11, 2014, 1:38:48 PM8/11/14
to django...@googlegroups.com
is data_modificacio a real field on your model? (not just a method?)

are you using a custom form?

somen...@gmail.com

unread,
Aug 11, 2014, 2:45:17 PM8/11/14
to django...@googlegroups.com
Yes, I'm pretty sure. You can see here my models. No 'modificacio'

And
$ grep -R "modificacio"
serviedre/tasques/models.py:    data_modificacio = models.DateTimeField(auto_now=True,verbose_name="data de modificació") # automàtic
serviedre/tasques/models.py:        ordering = ['ref', 'titol', 'estat', 'tipus', 'prioritat', 'data_modificacio', 'component']
serviedre/tasques/admin.py:        ('Data', {'fields': ['data_creacio', 'data_resolucio']}), # falta data_modificacio
serviedre/tasques/admin.py:    list_display = ('__str__', 'estat', 'tipus', 'prioritat', 'data_modificacio', 'component', 'edat')
Hi ha coincidències en el fitxer binari serviedre/tasques/__pycache__/admin.cpython-34.pyc
Hi ha coincidències en el fitxer binari serviedre/tasques/__pycache__/models.cpython-34.pyc
Hi ha coincidències en el fitxer binari serviedre/dades.sqlite3


El dilluns 11 d’agost de 2014 19:38:48 UTC+2, Collin Anderson va escriure:

Collin Anderson

unread,
Aug 11, 2014, 3:03:31 PM8/11/14
to django...@googlegroups.com
it could be an issue with auto_now, as only the database should be
editing that field and it shouldn't be editable through the admin.

Try adding this to your ResguardAdmin: readonly_fields = ['data_modificacio']

somen...@gmail.com

unread,
Aug 12, 2014, 5:18:44 AM8/12/14
to django...@googlegroups.com
Yes, it's.
Thank you very much.

This is not in the documentation this way. Can anyone update this?

El dilluns 11 d’agost de 2014 21:03:31 UTC+2, Collin Anderson va escriure:

Collin Anderson

unread,
Aug 12, 2014, 11:55:36 AM8/12/14
to django...@googlegroups.com
> This is not in the documentation this way. Can anyone update this?
See the note here:
https://docs.djangoproject.com/en/1.6/ref/models/fields/#django.db.models.DateField.auto_now
Reply all
Reply to author
Forward
0 new messages