Posted by & filed under python.

from espresa.helpers import JSONResponse

__author__ = 'dmitry'

from django.db import models
from django.test import TestCase
from rest_framework import serializers

class Album(models.Model):
    album_name = models.CharField(max_length=100)
    artist = models.CharField(max_length=100)

class Track(models.Model):
    album = models.ForeignKey(Album, related_name='tracks')
    order = models.IntegerField()
    title = models.CharField(max_length=100)
    duration = models.IntegerField()

    class Meta:
        unique_together = ('album', 'order')
        ordering = ['order']

    def __unicode__(self):
        return '%d: %s' % (self.order, self.title)

class TrackSerializer(serializers.ModelSerializer):
    class Meta:
        model = Track
        fields = ('order', 'title')

class AlbumSerializer(serializers.ModelSerializer):
    tracks = TrackSerializer(many=True, read_only=True)

    class Meta:
        model = Album
        fields = ('album_name', 'artist', 'tracks')

class OneTest(TestCase):
    def setUp(self):

    def tearDown(self):

    def test_ok(self):
        album = Album.objects.create(album_name='test name', artist='test artist')
        Track.objects.create(album=album, order=10, title='test title', duration=60)

        serializer = AlbumSerializer(Album.objects.all(), many=True)
        a = JSONResponse(, status=200)
        a = 1

Опубликовать в Facebook
Опубликовать в Google Plus

Leave a Reply

You must be logged in to post a comment.