danxshap / django-croppable-images

16 stars 6 forks source link

Using CroppableImageField in ModelForms #8

Closed phalt closed 11 years ago

phalt commented 11 years ago

Hey, we're trying to use django-croppable-images for our forms, but the readme is a little ambiguous on how to properly do this. Could you make an example in the readme or provide an example here?

This is what I'm doing currently:

models.py


from croppable.models import CroppableImageField
from croppable.utils import get_crop_processor

class Project(models.Model):

   image = CroppableImageField(
        invalidate_on_save=['project_page', 'preview_pitch'],
        upload_to="img/projectimage",
        blank=True)
    project_page = ImageSpec(
        get_crop_processor(image_field='image'),
        image_field='image')
    preview_pitch = ImageSpec(
        get_crop_processor(image_field='image'),
        image_field='image')

    ...

forms.py


from projects.models import Project
from croppable.forms import CroppableImageField

class MyModelForm(forms.ModelForm):

    class Meta:
        model = Project
        fields = ['image', 'title', 'content']

    image = CroppableImageField(blank=True)
    title = ...

When loading this form, all I get is the standard imagefield widget and it fails to save, with no issues or warnings, even with DEBUG = True.

If you can point me in the direction of this issue (I see there is another similar issue already opened) I'll be happy to fix and submit it.

phalt commented 11 years ago

Currently on Django 1.4.1

danxshap commented 11 years ago

Hmm, the code in the readme should be pretty thorough, in terms of outlining what you need to do to get this running, if I remember correctly (it's been a while)...

Can you confirm that the JS code is getting loaded in your browser?

Initially (i.e. nothing saved in your model/DB), you should see what looks like the standard ImageField widget (i.e. an html file input), but then once you select an image it should immediately be displayed in the page with the jCrop widget wired up. If that's not happening, it leads me to believe there is possibly a JS issue...

danxshap commented 11 years ago

Wait a minute, can you try reverting https://github.com/danxshap/django-croppable-images/commit/3a0a42ef4d5ce87e52d6cfb0434873d513ca26f1?

There was an annoying episode where I was fighting with different jQuery versions & Django Admin jQuery vs. our own jQuery, etc.. etc... and I think that commit may have introduced a change that makes this app only work in the Admin (very bad and inconsiderate of others on my part if that's the case).

danxshap commented 11 years ago

p.p.s. #6 is not related to this - that one is about using non-ModelForm, vanilla Django Form's, which you are not doing here.

phalt commented 11 years ago

Sure, I'll check those things out and report back. I noticed that commit might have something to do with it so I'll investigate more :+1:

phalt commented 11 years ago

I do get a javascript error, two in fact:

Uncaught ReferenceError: django is not defined

in these two files:

I'll use an earlier commit and test that out.

phalt commented 11 years ago

I used commit 805e6366206564eeb2b6294d9149ebdecca0fe9b and that solved this issue.

I'd suggest reverting the master back to this branch for now as it breaks in modelforms.

danxshap commented 11 years ago

Cool. Just want to confirm, croppable fields are working fine / as expected for you? And if so, what version of django image kit are you using?

phalt commented 11 years ago

Croppable image fields are working fine. Our django-imagekit version is 2.0.2

danxshap commented 11 years ago

Great, thanks.

On Thu, Jul 18, 2013 at 3:08 PM, Paul Hallett notifications@github.comwrote:

Croppable image fields are working fine. Our django-imagekit version is 2.0.2

— Reply to this email directly or view it on GitHubhttps://github.com/danxshap/django-croppable-images/issues/8#issuecomment-21206865 .