jonasundderwolf / django-image-cropping

Django helper application to easily and non-destructively crop arbitrarily large images in admin and frontend.
Other
553 stars 130 forks source link

ModelForm - ImageRatioField does not show Image (Django 1.11.1) #116

Closed fekoh closed 6 years ago

fekoh commented 7 years ago

Django==1.11.1 django-image-cropping==1.0.4 python 3.5.3

If i follow instructions how to add a cropping widget outside the admin, the ImageRatioField does not show any image.

Screenshot:

crop models.py

from django.db import models
from image_cropping import ImageCropField, ImageRatioField

class event(models.Model):
    date = models.DateField()
    name = models.CharField(max_length=512)
    flyer = ImageCropField(blank=True, upload_to='media')
    cropping = ImageRatioField('flyer', '60x60')

    def __str__(self):
        return self.name

forms.py

from django import forms
from .models import event

class addEventForm(forms.ModelForm):

    class Meta:
        model = event
        fields = ('date', 'name', 'flyer', 'cropping')

form.html

{% load cropping %}

<head>
{{ form.media }}
</head>

<body> 
<form method='POST' action="">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="submit">
</form>
</body>
coler-j commented 7 years ago

You figure this out? Mine only shows the image after saving the image to the model and reloading the form with the saved instance.

anrie commented 6 years ago

Does the example app that comes with django-image-cropping work for you?

fekoh commented 6 years ago

The example is working - just tried it.

$ pip freeze

Django==1.11.5
django-appconf==1.0.1
django-image-cropping==1.1.0
easy-thumbnails==2.4.2
olefile==0.44
Pillow==4.2.1
pkg-resources==0.0.0
pytz==2017.2
six==1.11.0

Screenshot:

screen

I will try later to implement it in my project.

Thank you for looking into/fixing it!

fekoh commented 6 years ago

Implemented it and works great. Thanks!