hovel / imagestore

Django gallery solution.
BSD 3-Clause "New" or "Revised" License
164 stars 72 forks source link

It is not possible to extend Image and Album #6

Closed aarcro closed 8 years ago

aarcro commented 12 years ago

Someone else raised the same issue I was having on stackoverflow: http://stackoverflow.com/questions/10250145/extending-imagestore-models/10577088#10577088

The solution there is mine.

I found that there is a circular import. Here's the order of things (slightly simplified):

  1. load_class(IMAGESTORE_ALBUM_MODEL)
  2. from imagestore.models.bases.album import BaseAlbum
  3. BaseAlbum has an FK to IMAGESTORE_IMAGE_MODEL (head), so it gets imported with load_class
  4. load_class(IMAGESTORE_IMAGE_MODEL)
  5. from imagestore.models.bases.image import BaseImage
  6. BaseImage has an FK to IMAGESTORE_ALBUM_MODEL (album), so it gets imported with load_class
  7. When this calls import IMAGESTORE_ALBUM_MODEL is already in sys.modules, though incomplete because it's still being built. And thus the module doesn't have an "Album" attribute yet.

The quick solution is to move the head field to models.album.Album and remove it from BaseAlbum. After doing this I was able to get the site running again. You must use the models package in your new app (not a simple models.py), with Image and Album in separate files.

lampslave commented 8 years ago

I think it was solved via #51.