django-serializer

How to display only values in Django Serializers?

☆樱花仙子☆ 提交于 2020-08-04 05:55:47
问题 I am implementing Django REST API framework using the 'rest_serializer' module: Currently the output is: { "count": 86, "next": "http://127.0.0.1:8000/state/?page=2", "previous": null, "results": [ { "state_name": "Alaska" }, { "state_name": "California" }, ... ] } How do I display just this as a json list: [ "Alaska", "California", ... ] Below are my serializers: from .models import States from rest_framework import serializers class StateSerializer(serializers.ModelSerializer): class Meta:

duplicate Key violation in Django insert doing after Django update

[亡魂溺海] 提交于 2020-07-23 06:10:24
问题 first i update my model instance, after that i tried to insert a new data but showing "IntegrityError('duplicate key value violates unique constraint "RFIDActivation_ActivationId_key"\nDETAIL: Key ("ActivationId")=(6de9ed9a) already exists.\n',)" Models.py class RFIDActivation(models.Model): RFIDActivationId = models.AutoField(primary_key=True, db_column='RFIDActivationId') Device = models.ForeignKey(Device, on_delete=models.CASCADE, db_column='DeviceId') Employee = models.ForeignKey(Employee

duplicate Key violation in Django insert doing after Django update

﹥>﹥吖頭↗ 提交于 2020-07-23 06:09:41
问题 first i update my model instance, after that i tried to insert a new data but showing "IntegrityError('duplicate key value violates unique constraint "RFIDActivation_ActivationId_key"\nDETAIL: Key ("ActivationId")=(6de9ed9a) already exists.\n',)" Models.py class RFIDActivation(models.Model): RFIDActivationId = models.AutoField(primary_key=True, db_column='RFIDActivationId') Device = models.ForeignKey(Device, on_delete=models.CASCADE, db_column='DeviceId') Employee = models.ForeignKey(Employee

duplicate Key violation in Django insert doing after Django update

不羁的心 提交于 2020-07-23 06:08:51
问题 first i update my model instance, after that i tried to insert a new data but showing "IntegrityError('duplicate key value violates unique constraint "RFIDActivation_ActivationId_key"\nDETAIL: Key ("ActivationId")=(6de9ed9a) already exists.\n',)" Models.py class RFIDActivation(models.Model): RFIDActivationId = models.AutoField(primary_key=True, db_column='RFIDActivationId') Device = models.ForeignKey(Device, on_delete=models.CASCADE, db_column='DeviceId') Employee = models.ForeignKey(Employee

Hide password field in GET but not POST in Django REST Framework where depth=1 in serializer

怎甘沉沦 提交于 2020-07-08 22:23:04
问题 I have 2 models : User & UserSummary. UserSummary has a foreign key to User. I just noticed that if I set depth= 1 within UserSummarySerializer , the password field is included in the output. It's hashed, but it would still be best to exclude this field. To hide the password field, I've just set the user field explicitly in the serializer, just like this : class UserSerializer(serializers.ModelSerializer): """A serializer for our user profile objects.""" class Meta: model = models.User extra

Hide password field in GET but not POST in Django REST Framework where depth=1 in serializer

余生颓废 提交于 2020-07-08 22:22:59
问题 I have 2 models : User & UserSummary. UserSummary has a foreign key to User. I just noticed that if I set depth= 1 within UserSummarySerializer , the password field is included in the output. It's hashed, but it would still be best to exclude this field. To hide the password field, I've just set the user field explicitly in the serializer, just like this : class UserSerializer(serializers.ModelSerializer): """A serializer for our user profile objects.""" class Meta: model = models.User extra

Hide password field in GET but not POST in Django REST Framework where depth=1 in serializer

落爺英雄遲暮 提交于 2020-07-08 22:19:59
问题 I have 2 models : User & UserSummary. UserSummary has a foreign key to User. I just noticed that if I set depth= 1 within UserSummarySerializer , the password field is included in the output. It's hashed, but it would still be best to exclude this field. To hide the password field, I've just set the user field explicitly in the serializer, just like this : class UserSerializer(serializers.ModelSerializer): """A serializer for our user profile objects.""" class Meta: model = models.User extra

Hide password field in GET but not POST in Django REST Framework where depth=1 in serializer

独自空忆成欢 提交于 2020-07-08 22:19:56
问题 I have 2 models : User & UserSummary. UserSummary has a foreign key to User. I just noticed that if I set depth= 1 within UserSummarySerializer , the password field is included in the output. It's hashed, but it would still be best to exclude this field. To hide the password field, I've just set the user field explicitly in the serializer, just like this : class UserSerializer(serializers.ModelSerializer): """A serializer for our user profile objects.""" class Meta: model = models.User extra

Serialize multiple InMemoryUploadedFile using ListField : Django REST Framework

故事扮演 提交于 2020-06-29 03:56:21
问题 How can I serialize multiple InMemoryUploadedFile using serializers.ListField() ?? code snippet #views.py @api_view(['POST', 'GET']) def create_post(request): if request.method == 'POST': altered_request_data = request.data.copy() in_memory_upload_files_list = [value for value in request.FILES.values()] altered_request_data['files'] = in_memory_upload_files_list serializer = PostSerializer(data=altered_request_data) serializer.is_valid(raise_exception=True) serializer.save() return Response