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 image is not being saved in the image field... #87

Open
swisscodes opened this issue Jun 3, 2021 · 0 comments
Open

the image is not being saved in the image field... #87

swisscodes opened this issue Jun 3, 2021 · 0 comments

Comments

@swisscodes
Copy link

swisscodes commented Jun 3, 2021

I have tried all possibilities with this process here I have my form below, everything works fine but after I clock on upload I get redirected to the detail page with the image displaying, so am thinking this is referring to the image URL, not the saved image

i first thought something was wrong with the way i setup media root or media url until i went to admin and uploaded an image manually and i saw everything is working fine.

here is save method

def save(self, force_insert=False, force_update=False, commit=True):
            image = super().save(commit=False)
            image_url = self.cleaned_data["url"]
            name = slugify(image.title)
            extension = image_url.rsplit(".", 1)[1].lower()
            image_name = f"{name}.{extension}"
            # download image from the given URL
            response = request.urlopen(image_url)
            image.image.save(image_name, ContentFile(response.read()), save=False)
            if commit:
                image.save()
            return image```


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant