GithubHelp home page GithubHelp logo

Comments (10)

Parbhat avatar Parbhat commented on June 23, 2024

we have to change reference in existing

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

to our new custom image model

from wagtail-cookiecutter-foundation.

chrisdev avatar chrisdev commented on June 23, 2024

@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

from wagtail-cookiecutter-foundation.

Parbhat avatar Parbhat commented on June 23, 2024

@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 😞

from wagtail-cookiecutter-foundation.

chrisdev avatar chrisdev commented on June 23, 2024

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.

from wagtail-cookiecutter-foundation.

Parbhat avatar Parbhat commented on June 23, 2024

@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.

from wagtail-cookiecutter-foundation.

chrisdev avatar chrisdev commented on June 23, 2024

@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.

from wagtail-cookiecutter-foundation.

Parbhat avatar Parbhat commented on June 23, 2024

@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

from wagtail-cookiecutter-foundation.

chrisdev avatar chrisdev commented on June 23, 2024

@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='+'
               )      

from wagtail-cookiecutter-foundation.

chrisdev avatar chrisdev commented on June 23, 2024

@Parbhat this is how it works in the Custom User Model https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#referencing-the-user-model

from wagtail-cookiecutter-foundation.

Parbhat avatar Parbhat commented on June 23, 2024

@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.

from wagtail-cookiecutter-foundation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.