D
D
dr sbtn2016-05-15 23:05:00
Django
dr sbtn, 2016-05-15 23:05:00

How to display "song - performers" data from the M2M connection in the admin panel?

how to make the list "artist - song name" displayed in the admin panel in Song? return what?

class Song(models.Model):
    name_song = models.CharField(max_length=30)
    ...
    musician = models.ManyToManyField(Musician)

    def __str__(self):
        return self.name_song

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dr sbtn, 2016-05-16
@dawasaturday

Roman Kitaev помог решить проблему:

def __str__(self):
  return '%s - %s' % (', '.join(map(str, self.musician.all())), self.name_song)

Владислав, 2016-05-15
@RGV

def __str__(self):
    return '{} - {}'.format(self.name_song, self.musician)

S
Skver0, 2016-05-16
@Skver0

admin.py

from django.contrib import admin
from models import *


class MusicianAdmin(admin.ModelAdmin):
    list_filter = ('musician', )
    filter_horizontal = ('musician', )

admin.site.register(Song, MusicianAdmin)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question