Created
February 20, 2015 22:51
-
-
Save miki725/1513401315f5b0fec670 to your computer and use it in GitHub Desktop.
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
from __future__ import unicode_literals, print_function | |
from django.db import models | |
class UniqueTogetherModel(models.Model): | |
foo = models.IntegerField() | |
bar = models.IntegerField() | |
class Meta(object): | |
unique_together = ('foo', 'bar') |
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
❯❯❯ ipython test.py | |
--------------------------------------------------------------------------- | |
AttributeError Traceback (most recent call last) | |
/Volumes/Data/Users/miki725/Development/libs/django-rest-framework-bulk/test.py in <module>() | |
35 | |
36 if __name__ == '__main__': | |
---> 37 example() | |
/Volumes/Data/Users/miki725/Development/libs/django-rest-framework-bulk/test.py in example() | |
31 ) | |
32 | |
---> 33 s.is_valid(raise_exception=True) | |
34 | |
35 | |
/Volumes/Data/Users/miki725/.virtualenvs/restbulk/lib/python3.4/site-packages/rest_framework/serializers.py in is_valid(self, raise_exception) | |
184 if not hasattr(self, '_validated_data'): | |
185 try: | |
--> 186 self._validated_data = self.run_validation(self.initial_data) | |
187 except ValidationError as exc: | |
188 self._validated_data = {} | |
/Volumes/Data/Users/miki725/.virtualenvs/restbulk/lib/python3.4/site-packages/rest_framework/serializers.py in run_validation(self, data) | |
513 return data | |
514 | |
--> 515 value = self.to_internal_value(data) | |
516 try: | |
517 self.run_validators(value) | |
/Volumes/Data/Users/miki725/.virtualenvs/restbulk/lib/python3.4/site-packages/rest_framework/serializers.py in to_internal_value(self, data) | |
543 for item in data: | |
544 try: | |
--> 545 validated = self.child.run_validation(item) | |
546 except ValidationError as exc: | |
547 errors.append(exc.detail) | |
/Volumes/Data/Users/miki725/.virtualenvs/restbulk/lib/python3.4/site-packages/rest_framework/serializers.py in run_validation(self, data) | |
364 value = self.to_internal_value(data) | |
365 try: | |
--> 366 self.run_validators(value) | |
367 value = self.validate(value) | |
368 assert value is not None, '.validate() should return the validated data' | |
/Volumes/Data/Users/miki725/.virtualenvs/restbulk/lib/python3.4/site-packages/rest_framework/fields.py in run_validators(self, value) | |
380 | |
381 try: | |
--> 382 validator(value) | |
383 except ValidationError as exc: | |
384 # If the validation error contains a mapping of fields to | |
/Volumes/Data/Users/miki725/.virtualenvs/restbulk/lib/python3.4/site-packages/rest_framework/validators.py in __call__(self, attrs) | |
137 self.enforce_required_fields(attrs) | |
138 queryset = self.queryset | |
--> 139 queryset = self.filter_queryset(attrs, queryset) | |
140 queryset = self.exclude_current_instance(attrs, queryset) | |
141 if queryset.exists(): | |
/Volumes/Data/Users/miki725/.virtualenvs/restbulk/lib/python3.4/site-packages/rest_framework/validators.py in filter_queryset(self, attrs, queryset) | |
116 for field_name in self.fields: | |
117 if field_name not in attrs: | |
--> 118 attrs[field_name] = getattr(self.instance, field_name) | |
119 | |
120 # Determine the filter keyword arguments and filter the queryset. | |
AttributeError: 'QuerySet' object has no attribute 'bar' |
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
# -*- coding: utf-8 -*- | |
from __future__ import print_function, unicode_literals | |
import django | |
django.setup() | |
from rest_framework.serializers import ModelSerializer | |
from rest_framework_bulk.tests.simple_app.models import UniqueTogetherModel | |
class ExampleSerializer(ModelSerializer): | |
class Meta(object): | |
model = UniqueTogetherModel | |
def example(): | |
UniqueTogetherModel.objects.all().delete() | |
obj = UniqueTogetherModel.objects.create(foo=1, bar=2) | |
s = ExampleSerializer( | |
UniqueTogetherModel.objects.all(), | |
data=[ | |
{ | |
'foo': 5, | |
'id': obj.pk, | |
} | |
], | |
partial=True, | |
many=True, | |
) | |
s.is_valid(raise_exception=True) | |
if __name__ == '__main__': | |
example() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment