Thanks for the pointer, I swear I had tried that quite a few times; but it started me in the right direction. I had a few issues with my __init__ declaration as well. I'll clean it up and post it on django snippets.
On May 15, 11:18 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Thu, May 15, 2008 at 10:53 AM, mikelostcause <[EMAIL PROTECTED]> wrote: > > > I have been searching and unable to find out why my script is not > > working correctly > > > If i take the required = False off of the image, the error "This field > > is required" get's thrown, else the 'image' field seems to not exist > > in the data as I now get 'No Data in Cleaned Data' error from the > > clean_image function. > > > Changing my image_clean function to pass back > > self.cleaned_data['image'] no matter what: > > post_data: {u'overview': [u''], u'image': [{'content': '<omitted>', > > 'content-type': 'image/jpeg', 'filename': 'test.jpg'}], u'blurb': > > [u''], u'title': [u'Test 3']} > > > cleaned_data: {'blurb': u'', 'image': None, 'overview': u'', 'public': > > False, 'team': [], 'title': u'Test 3'} > > > So the image looks to be in my post_data passed to the form, but it > > doesn't seem to make it out of the cleaning process. > > > ******* In my view ******** > > if pk: > > object_instance = > > get_object_or_404(model_class.objects.filter(parent_object=parent_object), > > pk=pk) > > else: > > object_instance = model_class() > > > if request.POST or request.FILES: > > post_data = request.POST.copy() > > post_data.update(request.FILES) > > form = ImportedModelForm(data=post_data, > > instance=object_instance, parent_object=parent_object) > > > if form.is_valid(): > > clean_data = form.cleaned_data > > error_list = form._errors > > > return render_to_response('template.html', {'profile': > > request.user, 'staff': staffUser, parent_object parent_object 'form': > > form, 'clean_data': clean_data, 'error_list': error_list }) > > > ********* In my forms ********* > > class ImportedModelForm(forms.ModelForm): > > image = forms.FileField(widget = forms.FileInput, required=False) > > > def __init__(self, parent_object=None, *args, **kwargs): > > super(ImportedModelForm, self).__init__(*args, **kwargs) > > self.fields['team'].queryset = > > Team.objects.filter(parent_object=parent_object) > > > def clean_image(self): > > if self.cleaned_data.get('image'): > > image_data = self.cleaned_data['image'] > > return image_data > > else: > > raise forms.ValidationError(_('No Data in Cleaned > > Data')) > > > class Meta: > > model = ImportedModel > > exclude = ('object1', 'object2') > > You're not following the correct recipe for binding uploaded file data to a > form. See: > > http://www.djangoproject.com/documentation/newforms/#binding-uploaded... > > Karen --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---