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

Problem to duplicate image inline #34

Open
martcot opened this issue Aug 14, 2018 · 4 comments
Open

Problem to duplicate image inline #34

martcot opened this issue Aug 14, 2018 · 4 comments

Comments

@martcot
Copy link

martcot commented Aug 14, 2018

Hi, I have some images in inline in my admin form and when I use Duplicate button it does not copy any images. Do you have any solution for this?

@igorsobreira
Copy link
Contributor

We don't copy the files, the new model will have paths to the same files are the original one.
https://github.com/RealGeeks/django-modelclone/blob/master/modelclone/admin.py#L115-L120

Maybe you can override save_model to customize how files are handled.

@martcot
Copy link
Author

martcot commented Aug 15, 2018

ok thanks. After clicked duplicate I see file link to my record but when I click Save I got validation error with files. I will check save_model thanks.

@pragex
Copy link

pragex commented Aug 17, 2018

The method save_model() isn't execute in this case.

@lockie
Copy link

lockie commented Oct 2, 2019

Seems like this happens when the image field is required, so form does not validate in the start of clone_view method. The following hack helped me:

class ModelAdmin(modelclone.ClonableModelAdmin):
    def get_form(self, request, *args, **kwargs):
        form = super().get_form(request, *args, **kwargs)
        if 'clone' in request.path:
            form.base_fields['my_image_field'].required = False
        return form

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

4 participants