-
Notifications
You must be signed in to change notification settings - Fork 153
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
Change Highlights's image field to use ImageChooserBlock #4349
Comments
Let's make this a staged PR:
|
This is a multi-step ticket so I don't think I can get it done and land it by tomorrow (the last day of this sprint). I'm moving it back to Stretch Goals. |
@Pomax @cadecairos If I'm reading the doc correctly, |
Blocked. Need a hand from Wagtail folks. From discussion on Slack,
Pomax has tried using |
/cc @phildexter |
Hi @mmmavis! You got about half way there, you're so close! To use the The tricky part is converting the FileField to an Image object. Depending on how big your database is I think you could do this in a single migration file but you'll need to do some hand-rolling in a data migration rather than a standard migration. Though that adds complexity and may not be what you're looking for, in which the multiple steps @cadecairos outlined would be good, it's just missing the conversion from a FileField to a ForeignKey. @register_snippet
class Highlight(SortableMixin):
...
image = models.ForeignKey(
'wagtailimages.Image', # Or path to custom Image class
help_text='...',
on_delete=models.CASCADE, # Or however you prefer to handle the on_delete method
blank=True,
null=True,
)
...
# Once you define panels, you'll need tp specify a panel type for all fields
# you want to be editable in the Wagtail admin
panels = [
FieldPanel("..."),
ImageChooserPanel("image"),
] Perviously I've handled that kind of conversion the "hacky" way with two fields and renaming them (again, like what @cadecairos had mentioned). Using your code, but I would have looped through the all the for highlight in Highlight.objects.all():
if highlight.image is supported_image_type(highlight.image):
image = Image.objects.create(...)
highlight.new_image_field = image
highlight.save() ☝️ Then the standard renaming migrations can be applied. I hope this unblocks you @mmmavis! Feel free to tag me for more input on the matter. |
Thanks for hopping in to help @KalobTaulien! Based on what you've said, I think this is then the steps to take here:
One potential gotcha: We store our files remotely on S3, do you know if |
Yep, that all looks good! I'm not 100% certain on the default file storage. I know S3 is supported in regards to file storage, but in terms of migrating a FileField to an Image FK I'm not too certain on. Maybe try creating a Wagtail Image manually from the data you have from the FileField and see if that works. Otherwise, I would err on the side of caution and I suspect (but don't know for sure) that when you delete the current Of course that leads us down the road of: what to do if images aren't deleted from S3 and you copy them for Wagtail Image objects? You could end up paying for 2x the storage and only using one set of images. That's something to look out for as well. |
Awaiting wagtail core support. |
given that this issue is over 2 years old, closing this as stale. |
https://github.com/mozilla/foundation.mozilla.org/blob/master/network-api/networkapi/highlights/models.py#L55-L60
Highlights
'simage
field to useImageChooserBlock
as images should have alt text associated with them.card
template accordingly.The text was updated successfully, but these errors were encountered: