Skip to content

Commit 096c58b

Browse files
committed
Merge branch 'master' into 3.0-beta
2 parents bc83dfe + 37312ee commit 096c58b

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

docs/tutorial/5-relationships-and-hyperlinked-apis.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ At the moment relationships within our API are represented by using primary keys
66

77
Right now we have endpoints for 'snippets' and 'users', but we don't have a single entry point to our API. To create one, we'll use a regular function-based view and the `@api_view` decorator we introduced earlier. In your `snippets/views.py` add:
88

9-
from rest_framework import renderers
109
from rest_framework.decorators import api_view
1110
from rest_framework.response import Response
1211
from rest_framework.reverse import reverse

docs/tutorial/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Create a new Django project named `tutorial`, then start a new app called `quick
1919
pip install djangorestframework
2020

2121
# Set up a new project with a single application
22-
django-admin.py startproject tutorial .
22+
django-admin.py startproject tutorial
2323
cd tutorial
2424
django-admin.py startapp quickstart
2525
cd ..

rest_framework/serializers.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ def get_fields(self):
721721
# arguments to deal with `unique_for` dates that are required to
722722
# be in the input data in order to validate it.
723723
hidden_fields = {}
724+
unique_constraint_names = set()
724725

725726
for model_field_name, field_name in model_field_mapping.items():
726727
try:
@@ -729,19 +730,20 @@ def get_fields(self):
729730
continue
730731

731732
# Include each of the `unique_for_*` field names.
732-
unique_constraint_names = set([
733+
unique_constraint_names |= set([
733734
model_field.unique_for_date,
734735
model_field.unique_for_month,
735736
model_field.unique_for_year
736737
])
737-
unique_constraint_names -= set([None])
738738

739-
# Include each of the `unique_together` field names,
740-
# so long as all the field names are included on the serializer.
741-
for parent_class in [model] + list(model._meta.parents.keys()):
742-
for unique_together_list in parent_class._meta.unique_together:
743-
if set(fields).issuperset(set(unique_together_list)):
744-
unique_constraint_names |= set(unique_together_list)
739+
unique_constraint_names -= set([None])
740+
741+
# Include each of the `unique_together` field names,
742+
# so long as all the field names are included on the serializer.
743+
for parent_class in [model] + list(model._meta.parents.keys()):
744+
for unique_together_list in parent_class._meta.unique_together:
745+
if set(fields).issuperset(set(unique_together_list)):
746+
unique_constraint_names |= set(unique_together_list)
745747

746748
# Now we have all the field names that have uniqueness constraints
747749
# applied, we can add the extra 'required=...' or 'default=...'
@@ -755,7 +757,7 @@ def get_fields(self):
755757
elif getattr(unique_constraint_field, 'auto_now', None):
756758
default = timezone.now
757759
elif unique_constraint_field.has_default():
758-
default = model_field.default
760+
default = unique_constraint_field.default
759761
else:
760762
default = empty
761763

0 commit comments

Comments
 (0)