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

The ordering column is not hidden with custom formset. #277

Open
sakimyto opened this issue Jun 1, 2021 · 0 comments
Open

The ordering column is not hidden with custom formset. #277

sakimyto opened this issue Jun 1, 2021 · 0 comments

Comments

@sakimyto
Copy link

sakimyto commented Jun 1, 2021

The ordering column is not hidden with custom formset.

For example:

models.py

class Post(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField()


class Image(models.Model):
    id = models.AutoField(primary_key=True)
    image = models.ImageField(verbose_name="画像")
    post = models.ForeignKey(Post, on_delete=models.CASCADE)
    sort = models.PositiveSmallIntegerField()

admin.py

class ImageInlineFormSet(BaseInlineFormSet):
    def clean(self):
        super(ImageInlineFormSet, self).clean()
        if not self.forms:
            raise ValidationError("Please add at least one post image.")


class ImageInline(SortableInlineAdminMixin, admin.TabularInline):
    model = Image
    formset = ImageInlineFormSet


class PostAdmin(admin.ModelAdmin):
    model = Post
    inlines = (ImageInline,)

Here's the problem:
When I try to add an image in ProductAdmin, I have to set sort manually.
This is not a serious problem, but I think that there is a better way.

image

A solution is to add adminsortable2.admin.CustomInlineFormSetMixin to ImageInlineFormSet.

admin.py

class ImageInlineFormSet(CustomInlineFormSetMixin, BaseInlineFormSet):
...

But 'CustomInlineFormSetMixin' is not declared in __all__.
So this is not a recommended method.

I want to know the best way.

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

1 participant