Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue in ImageThumbnailFileInput in django forms #142

Open
kartikdanidhariya opened this issue Mar 16, 2015 · 3 comments
Open

issue in ImageThumbnailFileInput in django forms #142

kartikdanidhariya opened this issue Mar 16, 2015 · 3 comments

Comments

@kartikdanidhariya
Copy link

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
Copy link
Collaborator

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
Copy link
Author

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

@gregmuellegger
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants