Tuesday, October 30, 2012

Re: Custom Admin Panel

On 30/10/2012 12:06, Bill Freeman wrote:
> On Mon, Oct 29, 2012 at 12:13 PM, Some Developer
> <someukdeveloper@gmail.com> wrote:
>> Hi,
>>
>> I'm in the process of writing a Django site and one of the requirements is
>> that it have a custom admin panel and a custom control panel but I am having
>> some problems coming up with the best way to organise my application.
>>
>> My initial idea was to have the admin (and control) panels as separate
>> applications with all the models that they require in specific apps. So for
>> instance if I have a news app then the admin panel simply loads the models
>> from the news app and displays them in the way that I want. This works fine
>> but it relies on a hard link between the admin panel and the news app. When
>> using the admin panel built into Django there is no hard link between apps,
>> you simply add an admin.py file to your application and the admin panel
>> takes care of the rest.
>>
>> Is there some way to do this with a custom admin panel whilst still
>> retaining the flexibility of displaying the data associated with an app in a
>> much more complex manner than the built in admin panel allows?
>>
>> I'm basically trying to decouple the two apps so that changes in one do not
>> have an adverse effect on the other one. Also it would be nice to use the
>> admin panel app in other projects that also require the flexibility of
>> having a custom admin panel.
>
> You could mimic the way that the native admin does it:
> admin.autodiscover() is called
> by your top level urls.py at the first request. It prances through the apps in
> django.conf.settings.INSTALLED_APPS and tries to import admin (admin.py) from
> each of them. The admin.py modules register the desired models with the admin
> interface. You would need to implement your own equivalent of
> admin.autodiscover()
> (and the root urls.py is a good place to call it), and either modifiy
> the admin.py files
> to register with your admin, or, better, have your autodiscover look
> for something
> else, like myadmin, or name_of_project_admin.
>
> But do realize that you can replace all of the templates that the
> existing admin uses
> just by putting your version in your top level templates directory
> (see the tutorial).
>
> You can even replace the admin views, by replacing the include of the
> native admin's
> urls by your own, and thus without monkey patching the admin. This leaves you
> free to take advantage of the native autodiscover (though that
> registry of apps may
> not be a public interface, and if not, not guaranteed to have a
> painless upgrade path).
> In this case you are free to use some of the native views and replace others, if
> desired.
>
> Bill

Thank you. Good advice.

I hadn't considered changing the included admin panel views. That may
work depending on whether I can perform some of the more complex
operations that I need.

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

No comments:

Post a Comment