Wednesday, March 6, 2013

Re: How to customize Django Admin interface with custom urls and views?

Hello John,
welcome in Django, hope you'll find it useful as I did.

Extend Django admin is a little bit tricky, but not impossible.

You can add your own views to admin simply by extending your ModelAdmin
subclass.
See
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_urls
for more info.

It's good practice to name your url pattern according to django
standard, otherwise it can get messy.
See
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#reversing-admin-urls
where you can find how to reverse admin urls and get the idea about
naming conventions. It's not mandatory, though.

Basicaly, you always need to have *view* and define *url*. There's no
*generic* pattern, like /module/controller/action/, you have to define
everything by yourself.

You can also create your own Admin site, subclass it, replace it,
whatever you want. You can have more than one admin site running along,
both for different tasks. There's more info at
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#hooking-adminsite-instances-into-your-urlconf

Final note: Django *is* MVC framework, but instead of controllers,
there are view and insted of views, there are templates. It works the same though.
See
https://docs.djangoproject.com/en/dev/faq/general/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-you-don-t-use-the-standard-names
for more info.


Hope I answered your questions. If you need more information, feel free to ask.

Cheers,
Tom


Dne Wed, 6 Mar 2013 08:36:06 -0800 (PST) John James
<jamesmayjones@gmail.com> napsal(a):

> Hi to all!
>
> I'm completely new in Django. All I done is read one Introduction Book by
> Adrian Holovaty.
> When I finished I thought I knew enough to build even something simple,
> because the book is real good and clear.
>
> Maybe I could create something simple, but I wanna create my own
> Administration interface with bunch of widgets, a lot of JS/AJAX nevermind.
>
> Anyway, when I tried to create one link by click on which an AJAX request
> should be sent to specific url. For example /admin/page/untouchData
>
> I have the *Page* model, and I need to perform some action named *untouchData.
> *But I dont know where should I define untouchData method, neither
> how could I make the Django know about my specific URL *untouchData*,
> because it's not the standard action, neither CRUD.
>
> For now I can't realize the concept of Django architecture, I mean MTV
> seems. I came from Yii PHP framework, it has MVC concept, so there I could
> create specific action in a Controller and all staff is done. Of course URL
> routing exists there too, but it's quite simple.
>
> I'm sure for Django it's not enough to create only one rule:
> *url(r'^admin/', include(admin.site.urls)),*
>
> So guys, could you please tell me where to read about this? Because I can't
> find an answer in three books and in Django Official Documentation too =(
>
> Thanks for advice anyway.
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment