praekelt/django-preferences

Enhancement: Use without django.contrib.sites

Opened this issue · 2 comments

rgov commented

This package did exactly what I needed, but it would be nice if it worked without django.contrib.sites. Almost certainly a vast majority of Django projects only have one site, and for them sites has some drawbacks.

  1. It adds a large "Sites" multiple selection form widget to the top of the preferences admin page which will only have one element anyway. (This form widget does not display the site name but the site domain, which is inconsistent with other parts of the UI.)

  2. It requires some additional configuration and throws errors when things aren't quite right.

  3. It creates a default example.com site which needs to be manually removed or removed with a custom migration for every deployment.

  4. It adds an undesired "Sites" section to Django Admin.

Idk if someone have this problem yet, but here my little contribution.
Usage indicates this:
from django.contrib import admin
from preferences.admin import PreferencesAdmin
from <my_app>.models import MyPreferences

admin.site.register(MyPreferences, PreferencesAdmin)

You can override exluding the field

class PreferencesAdminCustom(PreferencesAdmin):

exclude = ['sites']

admin.site.register(MyPreferences, PreferencesAdminCustom)

so you can add this code to your admin.py

from django.contrib import admin
from django.contrib.sites.models import Site

admin.site.unregister(Site)