Monday, July 30, 2012

Re: Read from an uploaded file and put data in a form for automatic Django validation

This works:

In forms.py:

class UploadForm(forms.Form):
  name = forms.CharField(label='name')
  addr1 = forms.CharField(label='addr1')

Interactive:

>>> from django import *
>>> from app.forms import *
>>> d = {'name': 'Fibber McGee', 'addr1': '79 Wistful Vista'}
>>> form = UploadForm(d)
>>> form.is_bound
True
>>> form.is_valid()
True
>>> form.cleaned_data
{'name': u'Fibber McGee', 'addr1': u'79 Wistful Vista'}
>>>

I get a bound form from this, and Django does the validation for me.


On Sun, Jul 29, 2012 at 12:37 PM, Derek <gamesbook@gmail.com> wrote:
Have a look at:
http://stackoverflow.com/questions/6091965/django-upload-a-file-and-read-its-content-to-populate-a-model



On Sunday, 29 July 2012 04:43:15 UTC+2, forthfan wrote:
Hi all,

Being lazy, I want Django to validate the stuff I read from an uploaded file as if it were being posted.  Is there a nice way to do this?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/kGJ40VUVY90J.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment