ratata
ratata

Reputation: 1169

wagtail 2.0 beta 'wagtaildocuments.Document' has not been loaded yet

I have installed the beta version of wagtail 2. Below is a code snippet from my project. When I try to makemigrations I get an error saying: ValueError: Cannot create form field for 'link_document' yet, because its related model 'wagtaildocuments.Document' has not been loaded yet

class LinkFields(models.Model):

    link_document = models.ForeignKey(
        'wagtaildocuments.Document',
        null=True,
        blank=True,
        related_name='+',
        on_delete=models.SET_NULL,
    )

    @property
    def link(self):
        return self.link_document.url


    panels = [
        DocumentChooserPanel('link_document'),
    ]

    class Meta:
        abstract = True

class CarouselItem(LinkFields):
    embed_url = models.URLField("Embed URL", blank=True)
    caption = models.CharField(max_length=255, blank=True)

    panels = [
        FieldPanel('embed_url'),
        FieldPanel('caption'),
        MultiFieldPanel(LinkFields.panels, "Link"),
    ]

    class Meta:
        abstract = True

I am using Django 2, Python 3.6, Wagtail 2.0b1

Upvotes: 0

Views: 346

Answers (1)

gasman
gasman

Reputation: 25227

The Document model in your ForeignKey should be referenced as 'wagtaildocs.Document', not 'wagtaildocuments.Document'.

While many of the module paths within Wagtail (as used in import lines, for example) have been updated for Wagtail 2.0, the app labels are unchanged. (It has to be done this way because the app label is just a single name like wagtailimages or wagtaildocs, with no dotted path to distinguish it: if it had been called images or documents instead, it would risk clashing with other apps in the project using that same name.) Model names within ForeignKey definitions are written as '<app_label>.<ModelName>', so wagtaildocs is the correct name to use here.

Upvotes: 1

Related Questions