django-admin2/docs/ref/modeladmin.rst

58 lines
1.7 KiB
ReStructuredText
Raw Permalink 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
2016-06-06 09:52:27 +00:00
from djadmin2.site import djadmin2_site
from djadmin2.types import ModelAdmin2
2013-07-27 04:59:48 +00:00
2016-06-06 09:52:27 +00:00
class PostAdmin(ModelAdmin2):
2013-07-27 04:59:48 +00:00
pass
2016-06-06 09:52:27 +00:00
djadmin2_site.register(Post, PostAdmin)
2013-07-27 04:59:48 +00:00
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
2016-06-06 09:52:27 +00:00
from djadmin2.site import djadmin2_site
from djadmin2.types import ModelAdmin2
2013-07-27 04:59:48 +00:00
2016-06-06 09:52:27 +00:00
class PostAdmin(ModelAdmin2):
2013-07-27 04:59:48 +00:00
preview_post = views.AdminView(r'^preview/$', views.PreviewPostView)
2016-06-06 09:52:27 +00:00
djadmin2_site.register(Post, PostAdmin)
2013-07-27 04:59:48 +00:00
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
2016-06-06 09:52:27 +00:00
from djadmin2.site import djadmin2_site
from djadmin2.types import ModelAdmin2
2013-07-27 04:59:48 +00:00
2016-06-06 09:52:27 +00:00
class PostAdmin(ModelAdmin2):
2013-07-27 04:59:48 +00:00
create_view = views.AdminView(r'^create/$', views.MyCustomCreateView)
2016-06-06 09:52:27 +00:00
djadmin2_site.register(Post, PostAdmin)