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

Unable to save inline models with a FileField and "sortable" enabled. #240

Closed
johnfkerbawy opened this issue Jun 2, 2014 · 7 comments
Closed

Comments

@johnfkerbawy
Copy link

Introducing a FileField into an inline that uses Django Suit's "sortable" functionality seems to break saving the inline object. I'm seeing "Please correct the error below." when selecting a file to upload and hitting "Save". The problem doesn't occur when the FileField is swapped out for a CharField, for example, and it also goes away when "sortable" isn't used.

suit_debug/models.py

from django.db import models

class Lasagna(models.Model):
    chef = models.CharField(max_length=10)

class Layer(models.Model):
    lasagna = models.ForeignKey('Lasagna', related_name='layers')
    # ingredient = models.CharField(max_length=100)
    ingredient = models.FileField(upload_to='wherever')
    order = models.PositiveIntegerField()

suit_debug/admin.py

from django import forms
from django.contrib import admin

import suit.admin

import suit_debug.models

class LayerInline(suit.admin.SortableStackedInline):
    extra = 1

    model = suit_debug.models.Layer

    sortable = 'order'

class LasagnaAdminForm(forms.ModelForm):
    class Meta:
        model = suit_debug.models.Lasagna

class LasagnaAdmin(admin.ModelAdmin):
    inlines = (
        LayerInline,
    )

    form = LasagnaAdminForm

admin.site.register(suit_debug.models.Lasagna, LasagnaAdmin)

Django==1.5.8
django-suit==0.2.8

FWIW, we paid for the "unlimited commercial" license and like it very much so far.

@darklow
Copy link
Owner

darklow commented Jun 3, 2014

I just tried adding FileField, choose file, hit save and it worked for me.
Here is the line i used:

image = models.FileField(upload_to='images', null=True, blank=True)

Are you sure this isn't file upload or another problem?

  1. Try removing SortableStackedInline and see if it works with original StackedInline class.
  2. If it still fails, could you please show me a screenshot of your Inline?
  3. Please check if there are no JS errors, when you hit save.

@johnfkerbawy
Copy link
Author

When using StackedInline, the sortable field is shown, and as long as it's filled in, the upload works fine. I don't see any JavaScript errors in Chrome's console.

Here's my test repo: https://github.com/jfk-urbandaddy/suit_debug/commits/master

Would you see if you can reproduce locally?

@mattbriancon
Copy link

Related to #232 and #216

@darklow
Copy link
Owner

darklow commented Jun 17, 2014

Thanks. Your test repo helped me reproduce the problem.
The problem occurred when FileField was only field in form.
Could you please try latest develop branch and confirm problem is fixed?

pip uninstall django-suit
pip install https://github.com/darklow/django-suit/tarball/develop

@johnfkerbawy
Copy link
Author

Thanks for looking into this. While I'm now able to upload multiple files, the ordering isn't persistent. If I use Suit's arrows after multiple files have been uploaded, after saving, the order resets to the original upload order.

@darklow
Copy link
Owner

darklow commented Jun 19, 2014

Could you please try now, should be fixed in latest develop.

@johnfkerbawy
Copy link
Author

All good. Thanks!

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

3 participants