P
P
Poul002020-10-01 20:38:40
Django
Poul00, 2020-10-01 20:38:40

How can I customize the output of playlists in Django?

How can I make a user's personal account, in which only playlists added by the users themselves were displayed? (I want to understand how to select data within controllers, I tried to study the controller class DetailView, but I didn’t understand anything, I would also like to know how selected data in
html.models.py

class tracks(models.Model):
  namem = models.CharField(max_length=50, null = True )
  track = models.FileField(upload_to = 'arch/for_playlists/')

class PlayList(models.Model):
  name = models.CharField(max_length = 100,verbose_name = 'Название')
  track = models.ManyToManyField(play_track,null = True)
  artist = models.ForeignKey(User,on_delete = models.CASCADE,null = True)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ilinykh, 2020-10-01
@Poul00

for starters, you don't have a playlist bound to a user
Inside View
playlists = PlayList.objects.filter(user=request.user).all()
return render(request, 'playlists.html', context={'playlists': playlists})
In playlists.html
{% for playlist in playlists %}
{{ playlists.name }}
{% endfor %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question