-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c7fc0f
commit b7b0d9b
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |