Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Extending AdminSite for custom views [RSS Feed]

#1 Dec. 11, 2010 18:18:24

William G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Extending AdminSite for custom views


Hello,

I am trying to extend AdminSite so I can provide custom views, so far
i have this:

class MyAdminSite(AdminSite):

def get_urls(self):
urls = super(self.__class__, self).get_urls()
my_urls = patterns('',
(r'^myview/$', self.admin_view(myview))
)
return my_urls + urls

myadmin = MyAdminSite()

admpattern = patterns('', (r'^admin/', include(myadmin.urls)),)

It works fine, except for one reason. I don't get any ModelAdmin
registered in this admin, because all external apps register it doing
admin.site.register().

I figured out do add the registered models from site instance to
myadmin through:
myadmin._registry = site._registry

But it doesn't feel right.

Anyone with experience in this could point me out to the most correct
answer for this problem?

Thank you!

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

Offline

#2 Dec. 12, 2010 14:28:54

Marcos M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Extending AdminSite for custom views


Add your custom urls before the admin include urls directive:
urlpatterns += patterns('',
(r'^admin/myview/$', 'your_admin_view'),
(r'^admin/', include(admin.site.urls)),
...

and continue working as usual. Django will go through the urls in descending
order matching your custom url before loading all the other admin urls.

Rgds,
Marcos


On Sat, Dec 11, 2010 at 1:33 PM, William Grzybowski <willia...@gmail.com>wrote:

> Hello,
>
> I am trying to extend AdminSite so I can provide custom views, so far
> i have this:
>
> class MyAdminSite(AdminSite):
>
> def get_urls(self):
> urls = super(self.__class__, self).get_urls()
> my_urls = patterns('',
> (r'^myview/$', self.admin_view(myview))
> )
> return my_urls + urls
>
> myadmin = MyAdminSite()
>
> admpattern = patterns('', (r'^admin/', include(myadmin.urls)),)
>
> It works fine, except for one reason. I don't get any ModelAdmin
> registered in this admin, because all external apps register it doing
> admin.site.register().
>
> I figured out do add the registered models from site instance to
> myadmin through:
> myadmin._registry = site._registry
>
> But it doesn't feel right.
>
> Anyone with experience in this could point me out to the most correct
> answer for this problem?
>
> Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>


--
Some people, when confronted with a problem, think “I know, I'll use regular
expressions.” Now they have two problems.

Jamie Zawinski, in comp.emacs.xemacs

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

Offline

  • Root
  • » Django
  • » Extending AdminSite for custom views [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support