~ubuntu-branches/ubuntu/jaunty/python-django/jaunty

« back to all changes in this revision

Viewing changes to docs/ref/contrib/databrowse.txt

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant, Eddy Mulyono
  • Date: 2008-09-16 12:18:47 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080916121847-mg225rg5mnsdqzr0
Tags: 1.0-1ubuntu1
* Merge from Debian (LP: #264191), remaining changes:
  - Run test suite on build.

[Eddy Mulyono]
* Update patch to workaround network test case failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.. _ref-contrib-databrowse:
 
2
 
 
3
==========
 
4
Databrowse
 
5
==========
 
6
 
 
7
.. module:: django.contrib.databrowse
 
8
   :synopsis: Databrowse is a Django application that lets you browse your data.
 
9
 
 
10
Databrowse is a Django application that lets you browse your data.
 
11
 
 
12
As the Django admin dynamically creates an admin interface by introspecting
 
13
your models, Databrowse dynamically creates a rich, browsable Web site by
 
14
introspecting your models.
 
15
 
 
16
.. admonition:: Note
 
17
 
 
18
    Databrowse is **very** new and is currently under active development. It
 
19
    may change substantially before the next Django release.
 
20
 
 
21
    With that said, it's easy to use, and it doesn't require writing any
 
22
    code. So you can play around with it today, with very little investment in
 
23
    time or coding.
 
24
 
 
25
How to use Databrowse
 
26
=====================
 
27
 
 
28
    1. Point Django at the default Databrowse templates. There are two ways to
 
29
       do this:
 
30
 
 
31
       * Add ``'django.contrib.databrowse'`` to your :setting:`INSTALLED_APPS`
 
32
         setting. This will work if your :setting:`TEMPLATE_LOADERS` setting
 
33
         includes the ``app_directories`` template loader (which is the case by
 
34
         default). See the :ref:`template loader docs <template-loaders>` for
 
35
         more.
 
36
 
 
37
       * Otherwise, determine the full filesystem path to the
 
38
         `:file:`django/contrib/databrowse/templates` directory, and add that
 
39
         directory to your :setting:`TEMPLATE_DIRS` setting.
 
40
 
 
41
    2. Register a number of models with the Databrowse site::
 
42
 
 
43
           from django.contrib import databrowse
 
44
           from myapp.models import SomeModel, SomeOtherModel
 
45
 
 
46
           databrowse.site.register(SomeModel)
 
47
           databrowse.site.register(SomeOtherModel)
 
48
 
 
49
       Note that you should register the model *classes*, not instances.
 
50
 
 
51
       It doesn't matter where you put this, as long as it gets executed at some
 
52
       point. A good place for it is in your :ref:`URLconf file
 
53
       <topics-http-urls>` (``urls.py``).
 
54
 
 
55
    3. Change your URLconf to import the :mod:`~django.contrib.databrowse` module::
 
56
 
 
57
           from django.contrib import databrowse
 
58
 
 
59
       ...and add the following line to your URLconf::
 
60
 
 
61
           (r'^databrowse/(.*)', databrowse.site.root),
 
62
 
 
63
       The prefix doesn't matter -- you can use ``databrowse/`` or ``db/`` or
 
64
       whatever you'd like.
 
65
 
 
66
    4. Run the Django server and visit ``/databrowse/`` in your browser.
 
67
 
 
68
Requiring user login
 
69
====================
 
70
 
 
71
You can restrict access to logged-in users with only a few extra lines of
 
72
code. Simply add the following import to your URLconf::
 
73
 
 
74
    from django.contrib.auth.decorators import login_required
 
75
 
 
76
Then modify the :ref:`URLconf <topics-http-urls>` so that the
 
77
:func:`databrowse.site.root` view is decorated with
 
78
:func:`django.contrib.auth.decorators.login_required`::
 
79
 
 
80
    (r'^databrowse/(.*)', login_required(databrowse.site.root)),
 
81
 
 
82
If you haven't already added support for user logins to your :ref:`URLconf
 
83
<topics-http-urls>`, as described in the :ref:`user authentication docs
 
84
<ref-contrib-auth>`, then you will need to do so now with the following
 
85
mapping::
 
86
 
 
87
    (r'^accounts/login/$', 'django.contrib.auth.views.login'),
 
88
 
 
89
The final step is to create the login form required by
 
90
:func:`django.contrib.auth.views.login`. The
 
91
:ref:`user authentication docs <ref-contrib-auth>` provide full details and a
 
92
sample template that can be used for this purpose.