admin.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ==============
  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 setting the
  8. :setting:`SESSION_COOKIE_DOMAIN` setting to match your domain. For example, if
  9. you're going to "https://www.example.com/admin/" in your browser, set
  10. ``SESSION_COOKIE_DOMAIN = 'www.example.com'``.
  11. 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.
  12. ===========================================================================================================================================================
  13. If you're sure your username and password are correct, make sure your user
  14. account has :attr:`~django.contrib.auth.models.User.is_active` and
  15. :attr:`~django.contrib.auth.models.User.is_staff` set to True. The admin site
  16. only allows access to users with those two fields both set to True.
  17. How do I automatically set a field's value to the user who last edited the object in the admin?
  18. ===============================================================================================
  19. The :class:`~django.contrib.admin.ModelAdmin` class provides customization hooks
  20. that allow you to transform an object as it saved, using details from the
  21. request. By extracting the current user from the request, and customizing the
  22. :meth:`~django.contrib.admin.ModelAdmin.save_model` hook, you can update an
  23. object to reflect the user that edited it. See :ref:`the documentation on
  24. ModelAdmin methods <model-admin-methods>` for an example.
  25. How do I limit admin access so that objects can only be edited by the users who created them?
  26. =============================================================================================
  27. The :class:`~django.contrib.admin.ModelAdmin` class also provides customization
  28. hooks that allow you to control the visibility and editability of objects in the
  29. admin. Using the same trick of extracting the user from the request, the
  30. :meth:`~django.contrib.admin.ModelAdmin.get_queryset` and
  31. :meth:`~django.contrib.admin.ModelAdmin.has_change_permission` can be used to
  32. control the visibility and editability of objects in the admin.
  33. My admin-site CSS and images showed up fine using the development server, but they're not displaying when using mod_wsgi.
  34. =========================================================================================================================
  35. See :ref:`serving the admin files <serving-the-admin-files>`
  36. in the "How to use Django with mod_wsgi" documentation.
  37. My "list_filter" contains a ManyToManyField, but the filter doesn't display.
  38. ============================================================================
  39. Django won't bother displaying the filter for a ``ManyToManyField`` if there
  40. are fewer than two related objects.
  41. For example, if your :attr:`~django.contrib.admin.ModelAdmin.list_filter`
  42. includes :doc:`sites </ref/contrib/sites>`, and there's only one site in your
  43. database, it won't display a "Site" filter. In that case, filtering by site
  44. would be meaningless.
  45. Some objects aren't appearing in the admin.
  46. ===========================================
  47. Inconsistent row counts may be caused by missing foreign key values or a
  48. foreign key field incorrectly set to :attr:`null=False
  49. <django.db.models.Field.null>`. If you have a record with a
  50. :class:`~django.db.models.ForeignKey` pointing to a non-existent object and
  51. that foreign key is included is
  52. :attr:`~django.contrib.admin.ModelAdmin.list_display`, the record will not be
  53. shown in the admin changelist because the Django model is declaring an
  54. integrity constraint that is not implemented at the database level.
  55. How can I customize the functionality of the admin interface?
  56. =============================================================
  57. You've got several options. If you want to piggyback on top of an add/change
  58. form that Django automatically generates, you can attach arbitrary JavaScript
  59. modules to the page via the model's class Admin :ref:`js parameter
  60. <modeladmin-asset-definitions>`. That parameter is a list of URLs, as strings,
  61. pointing to JavaScript modules that will be included within the admin form via
  62. a ``<script>`` tag.
  63. If you want more flexibility than simply tweaking the auto-generated forms,
  64. feel free to write custom views for the admin. The admin is powered by Django
  65. itself, and you can write custom views that hook into the authentication
  66. system, check permissions and do whatever else they need to do.
  67. If you want to customize the look-and-feel of the admin interface, read the
  68. next question.
  69. The dynamically-generated admin site is ugly! How can I change it?
  70. ==================================================================
  71. We like it, but if you don't agree, you can modify the admin site's
  72. presentation by editing the CSS stylesheet and/or associated image files. The
  73. site is built using semantic HTML and plenty of CSS hooks, so any changes you'd
  74. like to make should be possible by editing the stylesheet.
  75. What browsers are supported for using the admin?
  76. ================================================
  77. The admin provides a fully-functional experience to `YUI's A-grade`_ browsers,
  78. with the notable exception of IE6, which is not supported.
  79. There *may* be minor stylistic differences between supported browsers—for
  80. example, some browsers may not support rounded corners. These are considered
  81. acceptable variations in rendering.
  82. .. _YUI's A-grade: https://github.com/yui/yui3/wiki/Graded-Browser-Support