contrib.sites Admin problem

24 views
Skip to first unread message

Mike Dewhirst

unread,
Feb 4, 2020, 5:56:55 AM2/4/20
to django users
How do I control contrib.sites in the Admin?

I want to make it invisible to everyone except the superuser.

I have tried - inexpertly - to hijack the sites app in my own project
but it stubbornly insists on using its own admin.py

Thanks for switching on any light bulbs

Cheers

Mike

אורי

unread,
Feb 4, 2020, 6:48:44 AM2/4/20
to django...@googlegroups.com
Did you try `django_admin.site.unregister(Site)` before you register Site with your own admin?

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9eee993a-98d0-fa77-9e92-a8bd447af37d%40dewhirst.com.au.

maninder singh Kumar

unread,
Feb 4, 2020, 7:05:12 AM2/4/20
to django...@googlegroups.com
I believe the django templates used for admin are pretty good.  Are they as good as they claim ?

Sent from my iPad

Mike Dewhirst

unread,
Feb 4, 2020, 7:25:08 AM2/4/20
to django...@googlegroups.com
On 4/02/2020 5:47 pm, אורי wrote:
> Did you try `django_admin.site.unregister(Site)` before you register
> Site with your own admin?

Yes.

I have tried lots of things but I think I'm missing something very
basic. It must begin in settings.INSTALLED_APPS somehow. This is how it
is currently sitting:

#settings.py
INSTALLED_APPS = [
    ...
    #"django.contrib.sites",
    sites,
    ...
]

#<project>/sites/__init__.py
from django.contrib.sites import *

#<project>/sites/admin.py
from django.contrib import admin
from .models import Site

django.admin.site.unregister(Site)

class SiteAdmin(admin.ModelAdmin):
    list_display = ('domain', 'name')
    search_fields = ('domain', 'name')

    def has_view_permission(self, request=None, obj=None):
        return False    # request.user.is_superuser

admin.site.register(Site, SiteAdmin)

That "return False" line works properly when monkey-patching
contrib/sites/admin.py

Mike

>
> אורי
> u...@speedy.net <mailto:u...@speedy.net>
>
>
> On Tue, Feb 4, 2020 at 7:56 AM Mike Dewhirst <mi...@dewhirst.com.au
> <mailto:mi...@dewhirst.com.au>> wrote:
>
> How do I control contrib.sites in the Admin?
>
> I want to make it invisible to everyone except the superuser.
>
> I have tried - inexpertly - to hijack the sites app in my own project
> but it stubbornly insists on using its own admin.py
>
> Thanks for switching on any light bulbs
>
> Cheers
>
> Mike
>
> --
> 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...@googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> --
> 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...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABD5YeHi-N1wmz5buJgUEMfqRET5U6ZuFnSsOFSWp7iUOQWgjg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CABD5YeHi-N1wmz5buJgUEMfqRET5U6ZuFnSsOFSWp7iUOQWgjg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Mike Dewhirst

unread,
Feb 4, 2020, 7:28:46 AM2/4/20
to Django users
On 4/02/2020 6:03 pm, maninder singh Kumar wrote:
> I believe the django templates used for admin are pretty good.  Are
> they as good as they claim ?

Not sure what you are getting at here. They are very generic and I'm not
sure how I might intercept the sites template. Is that what you mean?

Mike

>
> Sent from my iPad
>
> On 04-Feb-2020, at 12:17 PM, אורי <u...@speedy.net
> <mailto:u...@speedy.net>> wrote:
>
>> Did you try `django_admin.site.unregister(Site)` before you register
>> Site with your own admin?
>>
>> אורי
>> u...@speedy.net <mailto:u...@speedy.net>
>>
>>
>> On Tue, Feb 4, 2020 at 7:56 AM Mike Dewhirst <mi...@dewhirst.com.au
>> <mailto:mi...@dewhirst.com.au>> wrote:
>>
>> How do I control contrib.sites in the Admin?
>>
>> I want to make it invisible to everyone except the superuser.
>>
>> I have tried - inexpertly - to hijack the sites app in my own
>> project
>> but it stubbornly insists on using its own admin.py
>>
>> Thanks for switching on any light bulbs
>>
>> Cheers
>>
>> Mike
>>
>> --
>> 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...@googlegroups.com
>> <mailto:django-users%2Bunsu...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/9eee993a-98d0-fa77-9e92-a8bd447af37d%40dewhirst.com.au.
>>
>> --
>> 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...@googlegroups.com
>> <mailto:django-users...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CABD5YeHi-N1wmz5buJgUEMfqRET5U6ZuFnSsOFSWp7iUOQWgjg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CABD5YeHi-N1wmz5buJgUEMfqRET5U6ZuFnSsOFSWp7iUOQWgjg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> --
> 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...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7F9FE9D3-8A04-46C8-8E71-A1D5A716A712%40gmail.com
> <https://groups.google.com/d/msgid/django-users/7F9FE9D3-8A04-46C8-8E71-A1D5A716A712%40gmail.com?utm_medium=email&utm_source=footer>.

Mike Dewhirst

unread,
Feb 4, 2020, 8:01:36 AM2/4/20
to django...@googlegroups.com
Tomorrow I'm going to examine contenttype permissions. Maybe that's
where to hide things.

Back in the am

Cheers

Mike

אורי

unread,
Feb 4, 2020, 9:31:51 AM2/4/20
to django...@googlegroups.com
How are your models defined in sites?


To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6b344f1c-e2ca-4933-9424-1ea1a57eab51%40dewhirst.com.au.

Mike Dewhirst

unread,
Feb 5, 2020, 1:31:07 AM2/5/20
to django...@googlegroups.com
On 4/02/2020 7:00 pm, Mike Dewhirst wrote:
> Tomorrow I'm going to examine contenttype permissions. Maybe that's
> where to hide things.

Yes indeed. Foot in mouth again. Removing view permissions to site
models drops it from the Admin.

Thank you Ori and  Maninder for taking time - sorry to bother you

Mike

maninder singh Kumar

unread,
Feb 6, 2020, 11:03:55 AM2/6/20
to django...@googlegroups.com
I figure that since only one kind of users, namely super or admin exist in django, it has got to be in the permissions.  As staff items are not objects.
 
               
 


To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b78e430d-23ec-c6bf-30b3-65dae9396bc5%40dewhirst.com.au.
Reply all
Reply to author
Forward
0 new messages