Django.fun

Django model many to many through not working

i have mysql database that are already made.
so models.py is created by manage.py inspectdb
and i add artists = models.ManyToManyField(Artist, related_name='songs', through = "ArtistSong") to Song table like this.

class Artist(models.Model):
    artist_id = models.IntegerField(primary_key=True)
    artist_name = models.TextField(blank=True, null=True)
    artist_main_genre = models.TextField(blank=True, null=True)
    
    class Meta:
        managed = False
        db_table = 'artist'

class Song(models.Model):
    song_id = models.IntegerField(primary_key=True)
    issue_date = models.TextField(blank=True, null=True)
    album_name = models.TextField(blank=True, null=True)
    album_id = models.IntegerField(blank=True, null=True)
    song_name = models.TextField(blank=True, null=True)
    added_cnt = models.IntegerField(blank=True, null=True)
    thumb_url = models.TextField(blank=True, null=True)
    artists = models.ManyToManyField(Artist, related_name='songs', through = "ArtistSong")

    class Meta:
        managed = False
        db_table = 'song'


class ArtistSong(models.Model):
    song = models.ForeignKey(Song, models.DO_NOTHING, blank=True, null=True)
    artist = models.ForeignKey(Artist, models.DO_NOTHING, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'artist_song'

i want get name and artist name of song. my views.py here.

class Songs(APIView):

    def get(self, request, *args, **kwargs):
        song_list= request.GET.get('song_list')
        queryset = Song.objects.filter(song_id__in = song_list)
        
        rec_songs = []
        for song in queryset.iterator():
            #for checking 
            print(song.song_name)
            print(song.artists.all())

            data = {
                'song_name' : song.song_name,
                'artist_name': [a.artist_name for a in song.artists.all()],
            }
            rec_songs.append(data)

        return Response(json.dumps(rec_songs,ensure_ascii = False))

print(song.song_name) shows song_name as i intened.
print(song.artists.all()) shows nothing but <QuerySet []>

please help!

Answers: 0