-
Hello everybody, i set up wagtailmedia on my wagtailproject. class FilmPage(Page):
body = RichTextField(blank=False)
featured_media = models.ForeignKey(
"wagtailmedia.Media",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
) I am able to display a media-file with this coding in my template: <video controls width="250">
<source src="{{ page.filmpage.featured_media.url }}" type="video/mp4" />
</video> But i don't know how to iterate through all media-files which are uploaded. Thnx for any help in advanced! |
Beta Was this translation helpful? Give feedback.
Answered by
zerolab
Jan 12, 2024
Replies: 1 comment 1 reply
-
Adding here what I posted in Slack: You will want to add that to the page context:
and your page template: {% if page.featured_video %}
<video controls width="250">
{% for source in page.featured_media.sources %}
<source src="{{ source.src }}" type="{{ source.type }}" />
{% endfor %}
</video>
{% endif %}
{% for video in all_videos %}
<video controls width="250">
{% for source in video.sources %}
<source src="{{ source.src }}" type="{{ source.type }}" />
{% endfor %}
</video>
{% endfor %} I would exclude def get_context(self, request):
context = super().get_context(request)
videos_qs = CustomMedia.objects.filter(type=MediaType.VIDEO)
if self.featured_media_id:
video_qs = video_qs.exclude(pk=self.featured_media_id)
context['all_videos'] = all_videos
return context |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
hzm74
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding here what I posted in Slack:
You will want to add that to the page context:
and your page template: