admin.txt 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. .. _faq-admin:
  2. FAQ: The admin
  3. ==============
  4. 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.
  5. ---------------------------------------------------------------------------------------------------------------------------
  6. The login cookie isn't being set correctly, because the domain of the cookie
  7. sent out by Django doesn't match the domain in your browser. Try these two
  8. things:
  9. * Set the ``SESSION_COOKIE_DOMAIN`` setting in your admin config file
  10. to match your domain. For example, if you're going to
  11. "http://www.example.com/admin/" in your browser, in
  12. "myproject.settings" you should set ``SESSION_COOKIE_DOMAIN = 'www.example.com'``.
  13. * Some browsers (Firefox?) don't like to accept cookies from domains that
  14. don't have dots in them. If you're running the admin site on "localhost"
  15. or another domain that doesn't have a dot in it, try going to
  16. "localhost.localdomain" or "127.0.0.1". And set
  17. ``SESSION_COOKIE_DOMAIN`` accordingly.
  18. 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.
  19. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  20. If you're sure your username and password are correct, make sure your user
  21. account has ``is_active`` and ``is_staff`` set to True. The admin site only
  22. allows access to users with those two fields both set to True.
  23. How can I prevent the cache middleware from caching the admin site?
  24. -------------------------------------------------------------------
  25. Set the :setting:`CACHE_MIDDLEWARE_ANONYMOUS_ONLY` setting to ``True``. See the
  26. :ref:`cache documentation <topics-cache>` for more information.
  27. How do I automatically set a field's value to the user who last edited the object in the admin?
  28. -----------------------------------------------------------------------------------------------
  29. The :class:`ModelAdmin` class provides customization hooks that allow you to transform
  30. an object as it saved, using details from the request. By extracting the current user
  31. from the request, and customizing the :meth:`ModelAdmin.save_model` hook, you can update
  32. an object to reflect the user that edited it. See :ref:`the documentation on ModelAdmin
  33. methods <model-admin-methods>` for an example.
  34. How do I limit admin access so that objects can only be edited by the users who created them?
  35. ---------------------------------------------------------------------------------------------
  36. The :class:`ModelAdmin` class also provides customization hooks that allow you to control the
  37. visibility and editability of objects in the admin. Using the same trick of extracting the
  38. user from the request, the :meth:`ModelAdmin.queryset` and :meth:`ModelAdmin.has_change_permission`
  39. can be used to control the visibility and editability of objects in the admin.
  40. My admin-site CSS and images showed up fine using the development server, but they're not displaying when using mod_python.
  41. ---------------------------------------------------------------------------------------------------------------------------
  42. See :ref:`serving the admin files <howto-deployment-modpython-serving-the-admin-files`
  43. in the "How to use Django with mod_python" documentation.
  44. My "list_filter" contains a ManyToManyField, but the filter doesn't display.
  45. ----------------------------------------------------------------------------
  46. Django won't bother displaying the filter for a ``ManyToManyField`` if there
  47. are fewer than two related objects.
  48. For example, if your ``list_filter`` includes ``sites``, and there's only one
  49. site in your database, it won't display a "Site" filter. In that case,
  50. filtering by site would be meaningless.
  51. How can I customize the functionality of the admin interface?
  52. -------------------------------------------------------------
  53. You've got several options. If you want to piggyback on top of an add/change
  54. form that Django automatically generates, you can attach arbitrary JavaScript
  55. modules to the page via the model's ``class Admin`` ``js`` parameter. That
  56. parameter is a list of URLs, as strings, pointing to JavaScript modules that
  57. will be included within the admin form via a ``<script>`` tag.
  58. If you want more flexibility than simply tweaking the auto-generated forms,
  59. feel free to write custom views for the admin. The admin is powered by Django
  60. itself, and you can write custom views that hook into the authentication
  61. system, check permissions and do whatever else they need to do.
  62. If you want to customize the look-and-feel of the admin interface, read the
  63. next question.
  64. The dynamically-generated admin site is ugly! How can I change it?
  65. ------------------------------------------------------------------
  66. We like it, but if you don't agree, you can modify the admin site's
  67. presentation by editing the CSS stylesheet and/or associated image files. The
  68. site is built using semantic HTML and plenty of CSS hooks, so any changes you'd
  69. like to make should be possible by editing the stylesheet. We've got a
  70. :ref:`guide to the CSS used in the admin <obsolete-admin-css>` to get you started.