0

I have to following code snippet which should return a correct url (relative or absolute)

class LinkFields(models.Model):
    link_external   = models.URLField("External link", blank=True)
    link_page       = models.ForeignKey('wagtailcore.Page', null=True, blank=True, related_name='+')
    link_document   = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, related_name='+' )

    @property
    def url(self):
        if self.link_page:
            return self.link_page.url
        elif self.link_document:
            return self.link_document.url
        else:
            return self.link_external

    panels = [
        FieldPanel('link_external'),
        PageChooserPanel('link_page'),
        DocumentChooserPanel('link_document'),
    ]

    class Meta:
        abstract = True

So if I use the ".url" property for a "wagtailcore.Page" a get an absolute url starting with "http" instead of "https".

What is the correct wagtail way to return a correct relative url or correct absolute url (leading with https in my case) within my "view/model"?

Thank you

Risadinha
  • 16,058
  • 2
  • 88
  • 91
Philipp S.
  • 827
  • 17
  • 41

1 Answers1

1

Wagtail should do that out of the box provided the base URL for the Site model is HTTPS.

There's a mailing list thread for this. https://groups.google.com/forum/#!topic/wagtail/atUeMXcNoCc

AKX
  • 152,115
  • 15
  • 115
  • 172