I am trying to create a connection between composer and performer in Django. I have the following models:
class Artist(models.Model):
gid = models.CharField(max_length=63, blank=True)
name = models.CharField(max_length=255, blank=True)
begin_life = models.CharField(max_length=31, blank=True)
end_life = models.CharField(max_length=31, blank=True)
type = models.CharField(max_length=1, blank=True)
gender = models.CharField(max_length=1, blank=True)
class Song(models.Model):
gid = models.CharField(max_length=63, blank=True)
title = models.CharField(max_length=255, blank=True)
artist = models.ForeignKey('Artist', related_name='songs_artist')
album = models.ForeignKey('Album', related_name='songs_album')
length = models.IntegerField(default=0)
I created my ArtistSerializer to get all artist songs when I get information about any particular artist. This is the created serializer:
class ArtistSerializer(serializers.ModelSerializer):
songs_artist = SongSerializer(source='songs_artist')
class Meta:
model = Artist
fields = ('name', 'type', 'gender', 'begin_life', 'end_life', 'songs_artist')
class SongSerializer(serializers.ModelSerializer):
artist = SongArtistSerializer()
album = SongAlbumSerializer()
class Meta:
model = Song
fields = ('id', 'title', 'artist', 'album', 'length')
class SongArtistSerializer(serializers.ModelSerializer):
class Meta:
model = Artist
fields = ('id', 'name')
My artist’s quick GET profiling revealed some troubling facts. The following are profiling results sorted by time and number of calls: http://pastebin.com/bwcKsn2i .
But, when I deleted the field songs_artistfrom my serializer, the following was the output of the profiler: http://pastebin.com/0s5k4w7i .
, 1240 , source!
?
.