2
0

admin.txt 6.1 KB

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