Require setting form_fields or exclude_form_fields on ModelViewSet when not providing a get_form_class method

This matches Django's current policy on ModelForms; form_fields = '__all__' can be used to restore the old 'all fields' behaviour.
pull/3545/merge
Matt Westcott 2017-06-09 20:00:01 +01:00
rodzic ba4a21687a
commit 280c317c68
1 zmienionych plików z 12 dodań i 1 usunięć
wagtail/wagtailadmin/viewsets

Wyświetl plik

@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals
from django.conf.urls import url
from django.core.exceptions import ImproperlyConfigured
from django.forms.models import modelform_factory
from wagtail.wagtailadmin.views import generic
@ -73,10 +74,20 @@ class ModelViewSet(ViewSet):
return db_field.formfield(**kwargs)
def get_form_class(self, for_update=False):
fields = getattr(self, 'form_fields', None)
exclude = getattr(self, 'exclude_form_fields', None)
if fields is None and exclude is None:
raise ImproperlyConfigured(
"Subclasses of ModelViewSet must specify 'get_form_class', 'form_fields' "
"or 'exclude_form_fields'."
)
return modelform_factory(
self.model,
formfield_callback=self.formfield_for_dbfield,
fields='__all__'
fields=fields,
exclude=exclude
)
def get_urlpatterns(self):