Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringProperty errors in ModelForm #225

Open
tonjo opened this issue Nov 5, 2013 · 3 comments
Open

StringProperty errors in ModelForm #225

tonjo opened this issue Nov 5, 2013 · 3 comments

Comments

@tonjo
Copy link
Contributor

tonjo commented Nov 5, 2013

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)

Tested with regular non-neo4django models and everything is fine.

Asked also a stackoverflow question.

@tonjo
Copy link
Contributor Author

tonjo commented Nov 5, 2013

As a workaround, I had to implement some kind of ModelForm myself.
Too hard for me to determine where the error is.

@amazure
Copy link

amazure commented Aug 9, 2014

I got this error when I created a ModelForm object with data that violated the unique constraint of a model field. Neo4django tries to get the correct error message for violating that constraint, but the corresponding entry does not exist in properties.Property.default_error_messages (properties.py line 42).

I know this is an old issue and I'm sure you moved on, but someone else might find this useful. Someone might also want to add 'unique' to Property.default_error_messages.

@tonjo
Copy link
Contributor Author

tonjo commented Oct 25, 2014

Thus is really a good "news" (even if dated a couple of months ago).
That project is quite sleeping, but I surely needed this, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants