- FAQ: The admin
- I can’t log in. When I enter a valid username and password, it just brings up the login page again, with no error messages.
- I can’t log in. When I enter a valid username and password, it brings up the login page again, with a “Please enter a correct username and password” error.
- How do I automatically set a field’s value to the user who last edited the object in the admin?
- How do I limit admin access so that objects can only be edited by the users who created them?
- My admin-site CSS and images showed up fine using the development server, but they’re not displaying when using mod_wsgi.
- My “list_filter” contains a ManyToManyField, but the filter doesn’t display.
- Some objects aren’t appearing in the admin.
- How can I customize the functionality of the admin interface?
- The dynamically-generated admin site is ugly! How can I change it?
- What browsers are supported for using the admin?
FAQ: The admin
I can’t log in. When I enter a valid username and password, it just brings up the login page again, with no error messages.
The login cookie isn’t being set correctly, because the domain of the cookiesent out by Django doesn’t match the domain in your browser. Try setting theSESSION_COOKIE_DOMAIN
setting to match your domain. For example, ifyou’re going to “https://www.example.com/admin/” in your browser, setSESSION_COOKIE_DOMAIN = 'www.example.com'
.
I can’t log in. When I enter a valid username and password, it brings up the login page again, with a “Please enter a correct username and password” error.
If you’re sure your username and password are correct, make sure your useraccount has is_active
andis_staff
set to True. The admin siteonly allows access to users with those two fields both set to True.
How do I automatically set a field’s value to the user who last edited the object in the admin?
The ModelAdmin
class provides customization hooksthat allow you to transform an object as it saved, using details from therequest. By extracting the current user from the request, and customizing thesave_model()
hook, you can update anobject to reflect the user that edited it. See the documentation onModelAdmin methods for an example.
How do I limit admin access so that objects can only be edited by the users who created them?
The ModelAdmin
class also provides customizationhooks that allow you to control the visibility and editability of objects in theadmin. Using the same trick of extracting the user from the request, theget_queryset()
andhas_change_permission()
can be used tocontrol the visibility and editability of objects in the admin.
My admin-site CSS and images showed up fine using the development server, but they’re not displaying when using mod_wsgi.
See serving the admin filesin the “How to use Django with mod_wsgi” documentation.
My “list_filter” contains a ManyToManyField, but the filter doesn’t display.
Django won’t bother displaying the filter for a ManyToManyField
if thereare fewer than two related objects.
For example, if your list_filter
includes sites, and there’s only one site in yourdatabase, it won’t display a “Site” filter. In that case, filtering by sitewould be meaningless.
Some objects aren’t appearing in the admin.
Inconsistent row counts may be caused by missing foreign key values or aforeign key field incorrectly set to null=False
. If you have a record with aForeignKey
pointing to a nonexistent object andthat foreign key is included islist_display
, the record will not beshown in the admin changelist because the Django model is declaring anintegrity constraint that is not implemented at the database level.
How can I customize the functionality of the admin interface?
You’ve got several options. If you want to piggyback on top of an add/changeform that Django automatically generates, you can attach arbitrary JavaScriptmodules to the page via the model’s class Admin js parameter. That parameter is a list of URLs, as strings,pointing to JavaScript modules that will be included within the admin form viaa <script>
tag.
If you want more flexibility than is feasible by tweaking the auto-generatedforms, feel free to write custom views for the admin. The admin is powered byDjango itself, and you can write custom views that hook into the authenticationsystem, check permissions and do whatever else they need to do.
If you want to customize the look-and-feel of the admin interface, read thenext question.
The dynamically-generated admin site is ugly! How can I change it?
We like it, but if you don’t agree, you can modify the admin site’spresentation by editing the CSS stylesheet and/or associated image files. Thesite is built using semantic HTML and plenty of CSS hooks, so any changes you’dlike to make should be possible by editing the stylesheet.
What browsers are supported for using the admin?
The admin provides a fully-functional experience to YUI’s A-grade browsers,with the notable exception of IE6, which is not supported.
There may be minor stylistic differences between supported browsers—forexample, some browsers may not support rounded corners. These are consideredacceptable variations in rendering.