import os

from django import forms
from django.db.models import get_model
from sample_project.article.widgets import FilePickerForm

from django.core.files.base import ContentFile

class ImageForm(forms.Form):
    pass
    
class PostAdminModelForm(forms.ModelForm):
    body = forms.CharField(widget=FilePickerForm())
    class Meta:
        model = get_model('article', 'post')
        

class AjaxImageForm(forms.ModelForm):
    file = forms.CharField(widget=forms.widgets.HiddenInput())    
    
    def clean_file(self):
        file = self.cleaned_data['file']
        if not os.path.exists(file):
            raise forms.ValidationErorr('Missing file')
        return file
        
    class Meta:
        model = get_model('article', 'image')
        exclude = ['file']
        
    def save(self, *args, **kwargs):
        item = super(AjaxImageForm, self).save(commit=False)
        item.file.save(self.cleaned_data['file'],
            ContentFile(open(str(self.cleaned_data['file']),'r').read())
        )
        item.save(*args, **kwargs)
        return item

@@ -1,15 +1,4 @@
-import os%0A%0A
 from
@@ -57,16 +57,17 @@
 t_model%0A
+%0A
 from sam
@@ -121,98 +121,8 @@
 rm%0A%0A
-from django.core.files.base import ContentFile%0A%0Aclass ImageForm(forms.Form):%0A    pass%0A    
 %0Acla
@@ -209,24 +209,25 @@
 ckerForm())%0A
+%0A
     class Me
@@ -279,697 +279,4 @@
 t')%0A
-        %0A%0Aclass AjaxImageForm(forms.ModelForm):%0A    file = forms.CharField(widget=forms.widgets.HiddenInput())    %0A    %0A    def clean_file(self):%0A        file = self.cleaned_data%5B'file'%5D%0A        if not os.path.exists(file):%0A            raise forms.ValidationErorr('Missing file')%0A        return file%0A        %0A    class Meta:%0A        model = get_model('article', 'image')%0A        exclude = %5B'file'%5D%0A        %0A    def save(self, *args, **kwargs):%0A        item = super(AjaxImageForm, self).save(commit=False)%0A        item.file.save(self.cleaned_data%5B'file'%5D,%0A            ContentFile(open(str(self.cleaned_data%5B'file'%5D),'r').read())%0A        )%0A        item.save(*args, **kwargs)%0A        return item%0A

clean out unused forms