# Path: examples/django_rest_framework/frontend/frontend/models.py
# class Account(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     email = models.CharField(max_length=30)
# 
#     api_base_name = 'accounts'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import AccountSerializer
#         return AccountSerializer
# 
# class Reporter(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     account = models.OneToOneField(Account)
#     first_name = models.CharField(max_length=30)
#     last_name = models.CharField(max_length=30)
# 
#     api_base_name = 'reporters'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import ReporterSerializer
#         return ReporterSerializer
# 
# class Article(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     headline = models.CharField(max_length=100)
#     pub_date = models.DateField()
#     reporter = models.ForeignKey(Reporter, related_name='articles')
# 
#     api_base_name = 'articles'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import ArticleSerializer
#         return ArticleSerializer
# 
# class Tag(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     label = models.CharField(max_length=30)
#     articles = models.ManyToManyField(Article, related_name='tags')
# 
#     api_base_name = 'tags'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import TagSerializer
#         return TagSerializer


from rest_framework import serializers
from .models import Account, Reporter, Article, Tag

class ArticleSerializer(serializers.ModelSerializer):
    reporter = ReporterSerializer()
    class Meta:
        model = Article
        fields = ('id', 'headline', 'pub_date', 'reporter')


class TagSerializer(serializers.ModelSerializer):
    articles = ArticleSerializer(many=True)
    class Meta:
        model = Tag
        fields = ('id', 'label', 'articles')


#
# Model serializers
# Reversed relationships applications
#


class ReversedTagSerializer(serializers.ModelSerializer):
    class Meta:
        model = Tag
        fields = ('id', 'label')


class ReversedArticleSerializer(serializers.ModelSerializer):
    tags = ReversedTagSerializer(many=True)
    class Meta:

# Path: examples/django_rest_framework/frontend/frontend/models.py
# class Account(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     email = models.CharField(max_length=30)
# 
#     api_base_name = 'accounts'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import AccountSerializer
#         return AccountSerializer
# 
# class Reporter(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     account = models.OneToOneField(Account)
#     first_name = models.CharField(max_length=30)
#     last_name = models.CharField(max_length=30)
# 
#     api_base_name = 'reporters'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import ReporterSerializer
#         return ReporterSerializer
# 
# class Article(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     headline = models.CharField(max_length=100)
#     pub_date = models.DateField()
#     reporter = models.ForeignKey(Reporter, related_name='articles')
# 
#     api_base_name = 'articles'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import ArticleSerializer
#         return ArticleSerializer
# 
# class Tag(CommonROAModel):
#     id = models.IntegerField(primary_key=True)  # don't forget it !
#     label = models.CharField(max_length=30)
#     articles = models.ManyToManyField(Article, related_name='tags')
# 
#     api_base_name = 'tags'
# 
#     @classmethod
#     def serializer(cls):
#         from .serializers import TagSerializer
#         return TagSerializer


# Path: examples/django_rest_framework/frontend/frontend/serializers.py
from rest_framework import serializers
from .models import Account, Reporter, Article, Tag


class ArticleSerializer(serializers.ModelSerializer):
    reporter = ReporterSerializer()
    class Meta:
        model = Article
        fields = ('id', 'headline', 'pub_date', 'reporter')


class TagSerializer(serializers.ModelSerializer):
    articles = ArticleSerializer(many=True)
    class Meta:
        model = Tag
        fields = ('id', 'label', 'articles')


#
# Model serializers
# Reversed relationships applications
#


class ReversedTagSerializer(serializers.ModelSerializer):
    class Meta:
        model = Tag
        fields = ('id', 'label')


class ReversedArticleSerializer(serializers.ModelSerializer):
    tags = ReversedTagSerializer(many=True)
    class Meta:

        model = Article