Skip to content

question: how to itterate through all media-files on a wagtailpage? #231

Answered by zerolab
hzm74 asked this question in Q&A
Discussion options

You must be logged in to vote

Adding here what I posted in Slack:

You will want to add that to the page context:

from wagtailmedia.models import Media, MediaType

# the import of the CustomMedia model if defined somewhere else

class FilmPage(Page):
    body = RichTextField(blank=False)
    featured_media = models.ForeignKey(
        "wagtailmedia.Media",
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="+",
    )
    # any other definitions

    def get_context(self, request):
        context = super().get_context(request)
        context['all_videos'] = CustomMedia.objects.filter(type=MediaType.VIDEO)
         
        return context

and your page template:

{% if page.f…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hzm74
Comment options

Answer selected by hzm74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #230 on January 12, 2024 23:28.