django-preferences icon indicating copy to clipboard operation
django-preferences copied to clipboard

Enhancement: Use without django.contrib.sites

Open rgov opened this issue 5 years ago • 2 comments

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.

rgov avatar Jan 19 '20 07:01 rgov

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)

manuellpsk avatar Apr 12 '22 22:04 manuellpsk

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)

yakimenko73 avatar Sep 12 '22 19:09 yakimenko73