jazzband / django-floppyforms

Full control of form rendering in the templates.
http://django-floppyforms.readthedocs.org/
Other
839 stars 145 forks source link

issue in ImageThumbnailFileInput in django forms #142

Open kartikdanidhariya opened 9 years ago

kartikdanidhariya commented 9 years ago

i am using django-floppyforms in my project but it can't get preview image in template i folow example from http://django-floppyforms.readthedocs.org/en/latest/examples.html#an-image-clearable-input-with-thumbnail

my forms.py

from django import forms
import datetime
from .models import Product
from hvad.forms import TranslatableModelForm
from ajax_upload.widgets import AjaxClearableFileInput
from django.utils.translation import ugettext_lazy as _
from crispy_forms.helper import FormHelper
from crispy_forms import layout, bootstrap
from crispy_forms.helper import FormHelper
#from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit, HTML

from floppyforms import ClearableFileInput
import floppyforms as forms

class ImageThumbnailFileInput(forms.ClearableFileInput):
    template_name = 'floppyforms/image_thumbnail.html'

class ProductForm(TranslatableModelForm):
    class Meta:
        model = Product
        fields = ('product_name','category','pro_image1','pro_image2','pro_image3','pro_image4','price','negotiable','des','dis_code')
        widgets = {'pro_image1': ImageThumbnailFileInput,
                   'pro_image2': ImageThumbnailFileInput,
                   'pro_image3': ImageThumbnailFileInput,
                   'pro_image4': ImageThumbnailFileInput,
                   }

my "models.py "

pro_image1 = models.FileField(upload_to='products/',blank=True, null=True, verbose_name = _('Product Image1')),
    pro_image2 = models.FileField(upload_to='products/',blank=True, null=True, verbose_name = _('Product Image2')),
    pro_image3 = models.FileField(upload_to='products/',blank=True, null=True, verbose_name = _('Product Image3')),
    pro_image4 = models.FileField(upload_to='products/',blank=True, null=True, verbose_name = _('Product Image4')),

image_thumbnail.html

{# image_thumbnail.html #}
{% load i18n %}
{% if value.url %}{% trans "Currently:" %} <a target="_blank" href="{{ value.url }}"><img src="{{ value.url }}" alt="{{ value }}" height="120"/></a>
{% if not required %}
<p><input type="checkbox" name="{{ checkbox_name }}" id="{{ checkbox_id }}">
<label for="{{ checkbox_id }}">{% trans "Clear" %}</label></p>
    {% else %}<br/>
{% endif %}
{% trans "Change:" %}
{% endif %}
<input type="{{ type }}" name="{{ name }}"{% if required %} required{% endif %}{% include "floppyforms/attrs.html" %}>

i also try with imagefields in models.py how can i solve this , Pls help!!!

gregmuellegger commented 9 years ago

Hi, you do import the original django forms which does not now anything about templates etc. Please import from floppyforms as described in the example you have mentioned. So replace the line:

from django import forms

with:

import floppyforms as forms

Good luck! I'm keen to hear if that did work for you.

kartikdanidhariya commented 9 years ago

I tried that but, It's not make any differance.

gregmuellegger commented 9 years ago

Can you please paste the relevant parts of the HTML output? I want to make sure that the image_thumbnail.html template is really rendered.