Skip to content

Commit

Permalink
Merge pull request #18 from yezyilomo/rename_pk_to_accept_pk
Browse files Browse the repository at this point in the history
Rename pk to accept pk
  • Loading branch information
yezyilomo authored Sep 6, 2019
2 parents 49997c3 + f737f72 commit 59a8ed8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ Response
<br>


### Using NestedField with `pk=True` kwarg.
`pk=True` is used if you want to update nested field by using id of existing data(basically associate and dessociate existing nested resources with the parent resource without actually mutating the nested resource). This applies to ForeignKey relation only.
### Using NestedField with `accept_pk=True` kwarg.
`accept_pk=True` is used if you want to update nested field by using pk/id of existing data(basically associate and dessociate existing nested resources with the parent resource without actually mutating the nested resource). This applies to ForeignKey relation only.

```python
from app.models import Location, Amenity, Property
Expand All @@ -149,7 +149,7 @@ class LocationSerializer(NestedModelSerializer):


class PropertySerializer(NestedModelSerializer):
location = NestedField(ocationSerializer, pk=True)
location = NestedField(ocationSerializer, accept_pk=True)
class Meta:
model = Property
fields = (
Expand Down
6 changes: 3 additions & 3 deletions drf_pretty_update/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class _WritableField(object):
pass

def BaseNestedFieldSerializerFactory(*args,
pk=False,
accept_pk=False,
create_ops=[ADD, CREATE],
update_ops=[ADD, CREATE, REMOVE, UPDATE],
serializer_class=None,
**kwargs):
BaseClass = _ReplaceableField if pk else _WritableField
BaseClass = _ReplaceableField if accept_pk else _WritableField

if not set(create_ops).issubset(set(CREATE_SUPPORTED_OPERATIONS)):
msg = (
Expand Down Expand Up @@ -172,7 +172,7 @@ def validate_data_based_nested(self, data):
return parent_serializer.validated_data

def to_internal_value(self, data):
if pk:
if accept_pk:
return self.validate_pk_based_nested(data)
return self.validate_data_based_nested(data)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name = 'drf-pretty-update',
version = '0.1.3',
version = '0.1.4',
description = DESCRIPTION,
long_description = readme,
long_description_content_type = 'text/markdown',
Expand Down
4 changes: 2 additions & 2 deletions tests/testapp/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class Meta:


class ReplaceableCourseSerializer(NestedModelSerializer):
books = NestedField(BookSerializer, pk=True, many=True, required=False)
books = NestedField(BookSerializer, accept_pk=True, many=True, required=False)

class Meta:
model = Course
fields = ['name', 'code', 'books']


class ReplaceableStudentSerializer(NestedModelSerializer):
course = NestedField(WritableCourseSerializer, pk=True)
course = NestedField(WritableCourseSerializer, accept_pk=True)
phone_numbers = PhoneSerializer(many=True, read_only=True)

class Meta:
Expand Down

0 comments on commit 59a8ed8

Please sign in to comment.