问题描述:

I have a very simple ModelForm subclass:

class UserPrefsForm(forms.ModelForm):

class Meta:

model = User

fields = ['first_name','last_name','username']

When I try to save the form in my view (only the post function here):

def post(self, request):

userform = UserPrefsForm(request.POST)

context = self.get_context_data()

if userform.is_valid():

userform.save()

else:

context['errors'] = True

return render(request,self.template_name,context)

I got this error:

AttributeError at /prefs

'super' object has no attribute 'error_messages'

Traceback:

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

115. response = callback(request, *callback_args, **callback_kwargs)

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/views/generic/base.py" in view

68. return self.dispatch(request, *args, **kwargs)

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/braces/views.py" in dispatch

107. request, *args, **kwargs)

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch

86. return handler(request, *args, **kwargs)

File "/home/tonjo/prj/tuned_prj/tuned_django/graph/views.py" in post

147. if userform.is_valid():

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/forms/forms.py" in is_valid

126. return self.is_bound and not bool(self.errors)

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/forms/forms.py" in _get_errors

117. self.full_clean()

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/forms/forms.py" in full_clean

274. self._post_clean()

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/forms/models.py" in _post_clean

344. self.validate_unique()

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/forms/models.py" in validate_unique

353. self.instance.validate_unique(exclude=exclude)

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/db/models/base.py" in validate_unique

731. errors = self._perform_unique_checks(unique_checks)

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/db/models/base.py" in _perform_unique_checks

831. errors.setdefault(key, []).append(self.unique_error_message(model_class, unique_check))

File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/db/models/base.py" in unique_error_message

882. return field.error_messages['unique'] % {

File "/home/tonjo/venv/tuned/src/neo4django/neo4django/utils.py" in __getattr__

303. return getattr(target, name)

I understand is the missing error_messages... Am I forced to define them?

相关阅读:
Top