Django queryset filter based on slug

I want to put a filter on a page which shows videos selecting an album shows up on album page not all the videos but my current filter is showing all the published videos. I couldn’t find a way to put a filter based on slug that if an album’s slug is matching with the current url then shows the video selecting that album. I am all confused help me.

enter image description here

models.py

from django.db import models
from django.urls import reverse

STATUS = (
    (1, "Publish"),
    (0, "Draft")
)

class WatchCategory(models.Model):
    title = models.CharField(max_length=20)
    slug = models.SlugField(max_length=2000, unique=True)

    def __str__(self):
        return self.title


class Genre(models.Model):
    title = models.CharField(max_length=20)
    slug = models.SlugField(max_length=2000, unique=True)

    def __str__(self):
        return self.title
    class Album(models.Model):
        title = models.CharField(max_length=2000)
        slug = models.SlugField(max_length=2000, unique=True)
        image = models.CharField(max_length=2000, blank=True)
    
        def __str__(self):
            return self.title
    
        def get_absolute_url(self):
            return reverse('Watch:album', kwargs={
                'slug': self.slug
            })
    
    
    class Video(models.Model):
        title = models.CharField(max_length=2000)
        slug = models.SlugField(max_length=2000, unique=True)
        thumbnail = models.CharField(max_length=2000, unique=True)
        updated_on = models.DateTimeField(auto_now=True)
        file = models.CharField(max_length=2000)
        time = models.CharField(max_length=2000, blank=True)
        about = models.TextField(blank=True)
        category = models.ManyToManyField(WatchCategory)
        album = models.ManyToManyField(Album)
        genre = models.ManyToManyField(Genre)
        created_on = models.DateTimeField(auto_now_add=True)
        status = models.IntegerField(choices=STATUS, default=1)
    
        class Meta:
            ordering = ['-created_on']
    
        def __str__(self):
            return self.title
    
        def get_absolute_url(self):
            return reverse('Watch:video', kwargs={
                'slug': self.slug
            })
    

views.py

        class Album(ListView):
            queryset = Video.objects.filter(status=1).order_by('-created_on')
            template_name = 'Watch/album.html'
            paginate_by = 6

            def get_context_data(self, **kwargs):
                context = super().get_context_data(**kwargs)
                context['title'] = 'Explore & Watch your favourite'
                return context

album.html

        {% extends "Watch/layout.html" %}
        {% load static %}
        {% block content %}

            <div class="video-block section-padding">
                <div class="row">
                    {% for video in video_list %}
                    <div class="col-xl-3 col-sm-6 mb-3">
                        <div class="video-card">
                            <div class="video-card-image">
                                <a class="play-icon" href="{% url 'Watch:video' video.slug %}"><i class="fas fa-duotone fa-circle-play"></i></a>
                                <a href="{% url 'Watch:video' video.slug %}"><img class="img-fluid" src="{{ video.thumbnail }}" alt=""></a>
                                <div class="time">{{ video.time }}</div>
                            </div>
                            <div class="video-card-body">
                                <div class="video-title">
                                    <a href="{% url 'Watch:video' video.slug %}">{{ video.title }}</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                </div>
            </div>

        {% endblock %}

I’m sorry, I’m not sure I’m following what you’re asking for here.

If I understand you correctly, you have the view Album which is a ListView.

Are you looking to add a filter to this view such that it reduces the number of entries being listed? Or are you looking for a view that will just show one instance of a Video? (Slug fields are unique, which means that searching for a matching slug can only ever retrieve one item.)

Side note: Please don’t add random or irrelevent images to your post.

Album is a ManyToManyField on Video so I want to appear Videos that are only selecting a specific album on the album page. For example:- Videos created by Gaurav should only visible on Gaurav’s album not anyone else.

So you want the set of Video for a given Album. This is a standard operation on a many-to-many field.

See the docs and examples at: