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

Custom image model creates problem with existing image fields #90

Closed
Parbhat opened this issue Jun 30, 2015 · 10 comments
Closed

Custom image model creates problem with existing image fields #90

Parbhat opened this issue Jun 30, 2015 · 10 comments

Comments

@Parbhat
Copy link
Collaborator

Parbhat commented Jun 30, 2015

selection_017

@Parbhat
Copy link
Collaborator Author

Parbhat commented Jun 30, 2015

we have to change reference in existing

image = models.ForeignKey(
    'wagtailimages.Image',
    ..
   )

to our new custom image model

@chrisdev
Copy link
Owner

@Parbhat Yes we'll have to write a data migration to migrate existing images to the new image model.
This will have to be documented so we may as well work out what has to be done and document it

@Parbhat
Copy link
Collaborator Author

Parbhat commented Jun 30, 2015

@chrisdev to update our existing ForeignKey from 'wagtailimages.Image' to 'photo_gallery.CustomImage' we have to create migrations files from start and then migrate. Fixtures also need to be updated again 😞

@chrisdev
Copy link
Owner

Bummer.
Maybe instead of a fixture we can use a sql dump as we said we want to enforce the use of Postgres?
How about leaving out the gallery_feed image for now? We can random select an image from the gallery to represent the feed image.

@Parbhat
Copy link
Collaborator Author

Parbhat commented Jul 1, 2015

@chrisdev we have to change ForeignKey in every app from pages to blog to our Custom Image model, if not the user will get the above error in screenshot while changing image. If I go for changing ForeignKey relationship after applying initial migrations then It creates a problem, the solution is to create migrations from start.

@chrisdev
Copy link
Owner

chrisdev commented Jul 1, 2015

@Parbhat Ok this is necessary only if they use the custom image model which is supposed to be optional
This is a if we are doing this we need to have some method of getting the image model just like how they do in in Django with the Auth model.

    get_image_model()

Also until we sort this out be need to put this in a branch. So that it would not affect the dev of other aspects of the project.

@Parbhat
Copy link
Collaborator Author

Parbhat commented Jul 1, 2015

@chrisdev I have migrated the existing ForeignKey relationships to our custom model and also created migrations and fixtures for that. Now it is working fine. In Wagtail, custom image model and wagtail image model can not work together. We have to choose one in a project. As per wagtail docs on advanced images - Any templates that reference the builtin image model will still continue to work as before but would need to be updated in order to see any new images. As torchbox folks also migrated to their custom image model -
https://github.com/torchbox/wagtail-torchbox/blob/master/torchbox/models.py

@chrisdev
Copy link
Owner

chrisdev commented Jul 1, 2015

@Parbhat Ok I get it but to make our stuff more reusable we should have a get_image_model() that returns the string module.Model of the custom image model this would work like

  from django.conf import settings
  def get_image_model()
       return settings.get('WAGTAILIMAGES_IMAGE_MODEL', 'wagtail.Images.ImageModel')

The image fields can the be defined as

       class MyPage(Page):
               ....
               feed_image = models.ForeignKey(get_image_model(), null=True, blank=True,
                       on_delete=models.SET_NULL, related_name='+'
               )      

@chrisdev
Copy link
Owner

chrisdev commented Jul 1, 2015

@Parbhat
Copy link
Collaborator Author

Parbhat commented Jul 1, 2015

@chrisdev this approach is good. But we have another problem. The problem is - we can not simply change the image model in models.ForeignKey() and run ./manage.py makemigrations and then ./manage.py migrate this breaks all. If get_image_model() returns a different model then all migrations have to be deleted first from migrations folder and then database have to be dropped and all process repeats.

Parbhat added a commit to Parbhat/wagtail-cookiecutter-foundation that referenced this issue Jul 1, 2015
chrisdev added a commit that referenced this issue Jul 2, 2015
Restored to Default Image model - Issue #42, #90
@chrisdev chrisdev closed this as completed Jul 9, 2015
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

2 participants