python - Django UUIDField issue -
i trying uuidfield work in python django using following model:
class ticket(models.model): id = models.uuidfield(primary_key=true, default=uuid.uuid4, editable=false) name = models.charfield(max_length=50)
however when try adding instance of model database returns following error: typeerror @ /tickets/ coercing unicode: need string or buffer, uuid found
the documentation of uuidfield short , doesn't me.
edit: did import uuid , here full traceback: environment:
request method: request url: http://127.0.0.1:8000/tickets/ django version: 1.8.5 python version: 2.7.9 installed applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'events', 'rest_framework') installed middleware: ('django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.auth.middleware.sessionauthenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware', 'django.middleware.security.securitymiddleware') traceback: file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 132. response = wrapped_callback(request, *callback_args, **callback_kwargs) file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view 58. return view_func(*args, **kwargs) file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/rest_framework/viewsets.py" in view 87. return self.dispatch(request, *args, **kwargs) file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/rest_framework/views.py" in dispatch 466. response = self.handle_exception(exc) file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/rest_framework/views.py" in dispatch 463. response = handler(request, *args, **kwargs) file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/rest_framework/mixins.py" in list 48. return response(serializer.data) file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/rest_framework/serializers.py" in data 663. ret = super(listserializer, self).data file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/rest_framework/serializers.py" in data 228. self._data = self.to_representation(self.instance) file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/rest_framework/serializers.py" in to_representation 603. self.child.to_representation(item) item in iterable file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/rest_framework/serializers.py" in to_representation 461. ret[field.field_name] = field.to_representation(attribute) file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/rest_framework/relations.py" in to_representation 356. name = self.get_name(value) file "/users/daviddejong/.virtualenvs/restdemo/lib/python2.7/site-packages/rest_framework/relations.py" in get_name 276. return six.text_type(obj) exception type: typeerror @ /tickets/ exception value: coercing unicode: need string or buffer, uuid found
edit 2: serializer looks this:
class ticketserializer(serializers.hyperlinkedmodelserializer): class meta: model = ticket fields = ('url', 'id', 'name')
edit 3:
i found error. made mistake in model. unicode looked this:
def __unicode__(self): return self.id
and of course not work.
Comments
Post a Comment