Merge pull request #437 from arthur-wsw/docs

Fix documentation examples
This commit is contained in:
Andrews Medina 2016-06-06 21:37:55 -03:00
commit ddd126abfc
7 changed files with 50 additions and 43 deletions

View file

@ -105,7 +105,7 @@ Add djadmin2 urls to your URLconf:
urlpatterns = [
...
url(r'^admin2/', include(djadmin2.default.urls)),
url(r'^admin2/', include(djadmin2_site.urls)),
]
@ -118,22 +118,22 @@ How to write django-admin2 modules
# Import your custom models
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.models import User
from djadmin2.site import djadmin2_site
from djadmin2.types import ModelAdmin2
from .models import Post, Comment
import djadmin2
class UserAdmin2(djadmin2.ModelAdmin2):
class UserAdmin2(ModelAdmin2):
# Replicates the traditional admin for django.contrib.auth.models.User
create_form_class = UserCreationForm
update_form_class = UserChangeForm
# Register each model with the admin
djadmin2.default.register(Post)
djadmin2.default.register(Comment)
djadmin2.default.register(User, UserAdmin2)
djadmin2_site.register(Post)
djadmin2_site.register(Comment)
djadmin2_site.register(User, UserAdmin2)
Migrating from 0.6.x
====================
@ -167,7 +167,7 @@ The default admin2 site has move into djadmin2.site make sure your use the news
urlpatterns = [
...
url(r'^admin2/', include(djadmin2.default.urls)),
url(r'^admin2/', include(djadmin2_site.urls)),
]
Migrating from 0.5.x

View file

@ -38,19 +38,19 @@ If you've worked with Django, this implementation should look familiar:
from .models import Post, Comment
import djadmin2
from djadmin2.site import djadmin2_site
from djadmin2.types import ModelAdmin2
class UserAdmin2(djadmin2.ModelAdmin2):
class UserAdmin2(ModelAdmin2):
create_form_class = UserCreationForm
update_form_class = UserChangeForm
# Register each model with the admin
djadmin2.default.register(Post)
djadmin2.default.register(Comment)
djadmin2.default.register(User, UserAdmin2)
djadmin2_site.register(Post)
djadmin2_site.register(Comment)
djadmin2_site.register(User, UserAdmin2)
.. _GitHub: https://github.com/twoscoops/django-admin2

View file

@ -45,7 +45,7 @@ Add djadmin2 urls to your URLconf:
urlpatterns = [
...
url(r'^admin2/', include(djadmin2.default.urls)),
url(r'^admin2/', include(djadmin2_site.urls)),
]
Development Installation
@ -86,7 +86,7 @@ The default admin2 site has move into djadmin2.site make sure your use the news
urlpatterns = [
...
url(r'^admin2/', include(djadmin2.default.urls)),
url(r'^admin2/', include(djadmin2_site.urls)),
]

View file

@ -54,11 +54,13 @@ In our blog/admin.py module we write:
.. code-block:: python
import djadmin2
from djadmin2.actions import BaseListAction
from djadmin2.site import djadmin2_site
from djadmin2.types import ModelAdmin2
from .models import Post, Comment
class DeleteAllComments(djadmin2.actions.BaseListAction):
class DeleteAllComments(BaseListAction):
description = 'Delete selected items'
default_template_name = 'actions/delete_all_comments_confirmation.html'
@ -74,11 +76,11 @@ In our blog/admin.py module we write:
custom_function_action.description = 'Do other action'
class PostAdmin(djadmin2.ModelAdmin2):
class PostAdmin(ModelAdmin2):
actions = [DeleteAllComments, custom_function_action]
djadmin2.default.register(Post, PostAdmin)
djadmin2.default.register(Comment)
djadmin2_site.register(Post, PostAdmin)
djadmin2_site.register(Comment)
.. warning::

View file

@ -23,18 +23,20 @@ Enter the following code in ``accounts/admin2.py``:
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
import djadmin2
from djadmin2.site import djadmin2_site
from djadmin2.forms import UserCreationForm, UserChangeForm
from djadmin2.types import ModelAdmin2
# fetch the User model
User = get_user_model()
# Incorporate the
class UserAdmin2(djadmin2.ModelAdmin2):
create_form_class = djadmin2.forms.UserCreationForm
update_form_class = djadmin2.forms.UserChangeForm
class UserAdmin2(ModelAdmin2):
create_form_class = UserCreationForm
update_form_class = UserChangeForm
djadmin2.default.register(User, UserAdmin2)
djadmin2.default.register(Group)
djadmin2_site.register(User, UserAdmin2)
djadmin2_site.register(Group)
Done! The User and Group controls will appear in your django-admin2 dashboard.

View file

@ -7,12 +7,13 @@ The `ModelAdmin2` class is the representation of a model in the admin interface.
.. code-block:: python
from .models import Post
import djadmin2
from djadmin2.site import djadmin2_site
from djadmin2.types import ModelAdmin2
class PostAdmin(djadmin2.ModelAdmin2):
class PostAdmin(ModelAdmin2):
pass
djadmin2.default.register(Post, PostAdmin)
djadmin2_site.register(Post, PostAdmin)
Adding a new view
=================
@ -29,12 +30,13 @@ is expected a string that is the name of your view.
from .models import Post
from djadmin2 import views
import djadmin2
from djadmin2.site import djadmin2_site
from djadmin2.types import ModelAdmin2
class PostAdmin(djadmin2.ModelAdmin2):
class PostAdmin(ModelAdmin2):
preview_post = views.AdminView(r'^preview/$', views.PreviewPostView)
djadmin2.default.register(Post, PostAdmin)
djadmin2_site.register(Post, PostAdmin)
Replacing an existing view
==========================
@ -46,9 +48,10 @@ the view that you want replace:
from .models import Post
from djadmin2 import views
import djadmin2
from djadmin2.site import djadmin2_site
from djadmin2.types import ModelAdmin2
class PostAdmin(djadmin2.ModelAdmin2):
class PostAdmin(ModelAdmin2):
create_view = views.AdminView(r'^create/$', views.MyCustomCreateView)
djadmin2.default.register(Post, PostAdmin)
djadmin2_site.register(Post, PostAdmin)

View file

@ -14,31 +14,31 @@ When you first log into django-admin2, just like ``django.contrib.admin`` you ar
However, because this is the dashboard view, the method of customization and configuration is different than other django-admin2 views.
In your Django project's root URLconf module (``urls.py``) modify the code to include the commented code before the ``djadmin2.default.autodiscover()``:
In your Django project's root URLconf module (``urls.py``) modify the code to include the commented code before the ``djadmin2_site.autodiscover()``:
.. code-block:: python
from django.conf.urls import patterns, include, url
import djadmin2
from djadmin2.site import djadmin2_site
from djadmin2.views import IndexView
######### Begin django-admin2 customization code
# Create a new django-admin2 index view
class IndexView(djadmin2.views.IndexView):
class CustomIndexView(IndexView):
# specify the template
default_template_name = "custom_dashboard_template.html"
# override the default index_view
djadmin2.default.index_view = IndexView
djadmin2_site.index_view = CustomIndexView
######### end django-admin2 customization code
djadmin2.default.autodiscover()
djadmin2_site.autodiscover()
urlpatterns = patterns('',
url(r'^admin2/', include(djadmin2.default.urls)),
url(r'^admin2/', include(djadmin2_site.urls)),
# ... Place the rest of the project URLs here
)