-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow type field on none polymorphic serializers (#376)
- Loading branch information
Showing
9 changed files
with
136 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.6 on 2017-10-11 06:31 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('example', '0003_polymorphics'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='AuthorType', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('modified_at', models.DateTimeField(auto_now=True)), | ||
('name', models.CharField(max_length=50)), | ||
], | ||
options={ | ||
'ordering': ('id',), | ||
}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='author', | ||
options={'ordering': ('id',)}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='authorbio', | ||
options={'ordering': ('id',)}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='blog', | ||
options={'ordering': ('id',)}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='comment', | ||
options={'ordering': ('id',)}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='entry', | ||
options={'ordering': ('id',)}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='taggeditem', | ||
options={'ordering': ('id',)}, | ||
), | ||
migrations.AlterField( | ||
model_name='entry', | ||
name='authors', | ||
field=models.ManyToManyField(related_name='entries', to='example.Author'), | ||
), | ||
migrations.AddField( | ||
model_name='author', | ||
name='type', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='example.AuthorType'), | ||
), | ||
] |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import pytest | ||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.core.urlresolvers import reverse | ||
|
@@ -226,3 +227,31 @@ def test_key_in_post(self): | |
self.assertEqual( | ||
get_user_model().objects.get(pk=self.miles.pk).email, | ||
'[email protected]') | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_patch_allow_field_type(author, author_type_factory, client): | ||
""" | ||
Verify that type field may be updated. | ||
""" | ||
author_type = author_type_factory() | ||
url = reverse('author-detail', args=[author.id]) | ||
|
||
data = { | ||
'data': { | ||
'id': author.id, | ||
'type': 'authors', | ||
'relationships': { | ||
'data': { | ||
'id': author_type.id, | ||
'type': 'author-type' | ||
} | ||
} | ||
} | ||
} | ||
|
||
response = client.patch(url, | ||
content_type='application/vnd.api+json', | ||
data=dump_json(data)) | ||
|
||
assert response.status_code == 200 |
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