django-admin2/docs/ref/modeladmin.rst

55 lines
1.5 KiB
ReStructuredText
Raw Normal View History

2013-07-27 04:59:48 +00:00
===========
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. Lets 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)