diff --git a/resources/admin/__init__.py b/resources/admin/__init__.py index 0b47800b7..d48ccae71 100644 --- a/resources/admin/__init__.py +++ b/resources/admin/__init__.py @@ -36,6 +36,7 @@ from ..models.utils import generate_id from munigeo.models import Municipality from rest_framework.authtoken.admin import Token +from respa_admin.forms import RespaMultiEmailField logger = logging.getLogger(__name__) @@ -144,12 +145,23 @@ def hard_delete_resources(modeladmin, request, queryset): hard_delete_resources.short_description = _('Hard delete selected resources') +class ResourceAdminForm(forms.ModelForm): + resource_staff_emails = RespaMultiEmailField( + required=False, + label=_('E-mail addresses for client correspondence') + ) + class Meta: + model = Resource + fields = '__all__' + class ResourceAdmin(PopulateCreatedAndModifiedMixin, CommonExcludeMixin, TranslationAdmin, HttpsFriendlyGeoAdmin): default_lon = 2478871 # Central Railway Station in EPSG:3857 default_lat = 8501259 default_zoom = 12 + form = ResourceAdminForm + list_display = ('name', 'unit', '_public', 'reservable', 'soft_deleted') list_filter = ('unit', '_public', 'reservable', 'soft_deleted') list_select_related = ('unit',) diff --git a/resources/fields.py b/resources/fields.py index 16a139748..d54b044c3 100644 --- a/resources/fields.py +++ b/resources/fields.py @@ -70,3 +70,6 @@ def get_db_prep_value(self, value, connection, prepared): if isinstance(value, list): return '\n'.join(value) return value + + def from_db_value(self, value, *args, **kwargs): + return self.to_python(value) diff --git a/respa_admin/forms.py b/respa_admin/forms.py index d7fc8adad..b5907867d 100644 --- a/respa_admin/forms.py +++ b/respa_admin/forms.py @@ -244,6 +244,9 @@ def to_python(self, value): if isinstance(value, list): return value return [val.strip() for val in value.splitlines() if val] + + def prepare_value(self, value): + return self.to_python(value) class ResourceForm(forms.ModelForm):