Skip to content

Commit

Permalink
added docs about AdminView.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsmedina committed Jul 27, 2013
1 parent 3c7fc0f commit b7b0d9b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Reference
ref/forms
ref/permissions
ref/views
ref/modeladmin
ref/built-in-views
ref/renderers
ref/meta
Expand Down
54 changes: 54 additions & 0 deletions docs/ref/modeladmin.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
===========
ModelAdmin2
===========

The `ModelAdmin2` class is the representation of a model in the admin interface. These are stored in a file named `admin2.py` in your application. Let’s take a look at a very simple example of the ModelAdmin2:

.. code-block:: python
from .models import Post
import djadmin2
class PostAdmin(djadmin2.ModelAdmin2):
pass
djadmin2.default.register(Post, PostAdmin)
Adding a new view
=================

To add a new view to a ModelAdmin2, it's need add an attribute that is an
instance of the `views.AdminView`.

The `view.AdminView` takes tree parameters: `url`, `view` and `name`.
The `url` is expected a string for the url pattern for your view.
The `view` is expected a view and `name` is an optional parameter and
is expected a string that is the name of your view.

.. code-block:: python
from .models import Post
from djadmin2 import views
import djadmin2
class PostAdmin(djadmin2.ModelAdmin2):
preview_post = views.AdminView(r'^preview/$', views.PreviewPostView)
djadmin2.default.register(Post, PostAdmin)
Replacing an existing view
==========================

To replacing an existing admin view, it's need add an attribute with the same name that
the view that you want replace:

.. code-block:: python
from .models import Post
from djadmin2 import views
import djadmin2
class PostAdmin(djadmin2.ModelAdmin2):
create_view = views.AdminView(r'^create/$', views.MyCustomCreateView)
djadmin2.default.register(Post, PostAdmin)

0 comments on commit b7b0d9b

Please sign in to comment.