Я следовал руководству https://docs.wagtail.io/en/v2.6.2/getting_started/tutorial.html и добавил в свое приложение блога class BlogPageGalleryImage(Orderable):
, затем def main_image(self):
в class BlogPage(Page):
, который работал.Но у меня есть еще два приложения ( проекты и события ) с экземплярами страниц, аналогичными blog , и я не могу добавить к ним галереи таким же образом.Должен ли я внедрить галерею в сам класс Page?
У меня есть 4 приложения (блог, информация о событиях, проектах) и в определениях моделей * IndexPage, * Page, * PageGalleryImages соответственно.
Например, в файле models.py I приложения событийопределено
class EventPageGalleryImages(Orderable):
page = ParentalKey(EventPage, on_delete=models.CASCADE, related_name='gallery_images')
image = models.ForeignKey( 'wagtailimages.Image', on_delete=models.CASCADE, related_name='+' )
caption = models.CharField(blank=True, max_length=250)
panels = [ ImageChooserPanel('image'), FieldPanel('caption'), ]
, но я получаю ошибку при makemigrations:
(ma_env) ➜ ma_app git:(0.15) ✗ ./manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/DEV/ma_env/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/DEV/ma_env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/DEV/ma_env/lib/python3.6/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
raise _exception[1]
File "/home/DEV/ma_env/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "/home/DEV/ma_env/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/DEV/ma_env/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/DEV/ma_env/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/DEV/ma_env/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/DEV/ma_app/events/models.py", line 24, in <module>
class EventPage(Page):
File "/home/DEV/ma_app/events/models.py", line 53, in EventPage
class EventPageGalleryImages(Orderable):
File "/home/DEV/ma_app/events/models.py", line 54, in EventPageGalleryImages
page = ParentalKey(EventPage, on_delete=models.CASCADE, related_name='gallery_images')
NameError: name 'EventPage' is not defined