I have a Playlist Model and a Track model.
class Playlist(models.Model):
created = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User, related_name="playlists")
class Track(models.Model):
playlist = models.ForeignKey(Playlist, related_name="tracks")
track_id = models.CharField(max_length=50)
And the serializers:
class TrackSerializer(serializers.ModelSerializer):
class Meta:
model = Track
fields = ("id", "track_id")
class PlaylistSerializer(serializers.ModelSerializer):
user = serializers.Field(source="user.username")
tracks = TrackSerializer(many=True)
class Meta:
model = Playlist
fields = ("id", "created", "user", "tracks")
How would I go about creating views (using viewsets preferably) that allow me list a playlist's tracks at playlists/<playlist_id>
and also create tracks at the same url?
I currently get non_field_errors
when I go to the above url.
Couldn't find much on how to do these nested views on the docs. Thanks.