def attachedimage_form_factory(lang='en', debug=False):
    ''' Returns ModelForm class to be used in admin.
        'lang' is the language for GearsUploader (can be 'en' and 'ru' at the
        moment).
    '''
    yui = '' if debug else '.yui'
    class _AttachedImageAdminForm(forms.ModelForm):

        caption = forms.CharField(label=_('Caption'), required=False)

        class Media:
            js = [
                  'generic_images/js/mootools-1.2.4-core-yc.js',
                  'generic_images/js/GearsUploader.%s%s.js' % (lang, yui,),
                  'generic_images/js/AttachedImageInline.js',
            ]

        class Meta:
            model = AttachedImage
    return _AttachedImageAdminForm