Skip to content

Commit

Permalink
Merge pull request #437 from arthur-wsw/docs
Browse files Browse the repository at this point in the history
Fix documentation examples
  • Loading branch information
andrewsmedina committed Jun 7, 2016
2 parents 59197a4 + 8e8b48a commit ddd126a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 43 deletions.
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
]
Expand All @@ -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
====================
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)),
]
Expand Down
12 changes: 7 additions & 5 deletions docs/ref/actions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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::
Expand Down
14 changes: 8 additions & 6 deletions docs/ref/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
21 changes: 12 additions & 9 deletions docs/ref/modeladmin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=================
Expand All @@ -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
==========================
Expand All @@ -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)
14 changes: 7 additions & 7 deletions docs/ref/views.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit ddd126a

Please sign in to comment.