-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add todo repro app * Add explicit test against model named "Nested" * Force serializers named NestedSerializer to be output as inline models * Allow ref_name to rescue a NestedSerializer * Add tests and documentation
- Loading branch information
Showing
15 changed files
with
326 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
'snippets', | ||
'users', | ||
'articles', | ||
'todo', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2018-02-21 23:26 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Todo', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=50)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='TodoAnother', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=50)), | ||
('todo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='todo.Todo')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='TodoYetAnother', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=50)), | ||
('todo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='todo.TodoAnother')), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.db import models | ||
|
||
|
||
class Todo(models.Model): | ||
title = models.CharField(max_length=50) | ||
|
||
|
||
class TodoAnother(models.Model): | ||
todo = models.ForeignKey(Todo, on_delete=models.CASCADE) | ||
title = models.CharField(max_length=50) | ||
|
||
|
||
class TodoYetAnother(models.Model): | ||
todo = models.ForeignKey(TodoAnother, on_delete=models.CASCADE) | ||
title = models.CharField(max_length=50) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from rest_framework import serializers | ||
|
||
from .models import Todo, TodoAnother, TodoYetAnother | ||
|
||
|
||
class TodoSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Todo | ||
fields = ('title',) | ||
|
||
|
||
class TodoAnotherSerializer(serializers.ModelSerializer): | ||
todo = TodoSerializer() | ||
|
||
class Meta: | ||
model = TodoAnother | ||
fields = ('title', 'todo') | ||
|
||
|
||
class TodoYetAnotherSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = TodoYetAnother | ||
fields = ('title', 'todo') | ||
depth = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from rest_framework import routers | ||
|
||
from todo import views | ||
|
||
router = routers.DefaultRouter() | ||
router.register(r'', views.TodoViewSet) | ||
router.register(r'another', views.TodoAnotherViewSet) | ||
router.register(r'yetanother', views.TodoYetAnotherViewSet) | ||
|
||
urlpatterns = router.urls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from rest_framework import viewsets | ||
|
||
from .models import Todo, TodoAnother, TodoYetAnother | ||
from .serializer import TodoAnotherSerializer, TodoSerializer, TodoYetAnotherSerializer | ||
|
||
|
||
class TodoViewSet(viewsets.ReadOnlyModelViewSet): | ||
queryset = Todo.objects.all() | ||
serializer_class = TodoSerializer | ||
|
||
|
||
class TodoAnotherViewSet(viewsets.ReadOnlyModelViewSet): | ||
queryset = TodoAnother.objects.all() | ||
serializer_class = TodoAnotherSerializer | ||
|
||
|
||
class TodoYetAnotherViewSet(viewsets.ReadOnlyModelViewSet): | ||
queryset = TodoYetAnother.objects.all() | ||
serializer_class = TodoYetAnotherSerializer |
Oops, something went wrong.