Adarsha B.G
Adarsha B.G

Reputation: 132

How to display the list of videos in two categories 1.'currentUser' videos and 2. 'otherUsers' videos within same class in django

The below code gives "otherUsers" videos

class Test(ListView):
    model = VideoUpload
    template_name = 'videoTube.html'

The below code gives "currentUser" videos

class Test(ListView):
    model = VideoUpload
    template_name = 'videoTube.html'

    def get_queryset(self):
        return VideoUpload.objects.filter(user=self.request.user)

In templates

{% for vid in object_list %}
  {% if forloop.counter < 5 %}
    {{ vid.video }}
  {% endif %}
{% endfor %}

My requirement is to display the list of videos in two categories 1.List of 'currentUser' videos and 2.List of 'otherUsers' videos within same class 'Test' which should display on the same html page

Upvotes: 0

Views: 26

Answers (1)

Andrey Maslov
Andrey Maslov

Reputation: 1466

you need to define method

def get_context_data(self, **kwargs):
  context = super().get_context_data(**kwargs)
  context["other_video_list"] = VideoUpload.objects.exclude(user=self.request.user)
  return context

and then in your template you can use

{% for other_vid in other_video_list %}
  ...
{% endfor %}

Upvotes: 1

Related Questions