django-rest-framework

How to add data to nested serializers?

泄露秘密 提交于 2020-07-28 04:46:10
问题 I'm trying to add data to my database by rest API and I have some problems with adding the data. So basically I have added this data from the admin page, but I want to add this from my other python by using requests. When I'm sending post request it shows me that it has been added, but sensor array is empty [ { "id": 1, "name": "Stacja 1", "delay_time": 123, "sensor": [ { "id": 1, "name": "DS18B20", "type": "temperature", "date_created": "2020-06-26T16:30:28.657804Z", "value": 123.0, "index":

How to add data to nested serializers?

丶灬走出姿态 提交于 2020-07-28 04:44:46
问题 I'm trying to add data to my database by rest API and I have some problems with adding the data. So basically I have added this data from the admin page, but I want to add this from my other python by using requests. When I'm sending post request it shows me that it has been added, but sensor array is empty [ { "id": 1, "name": "Stacja 1", "delay_time": 123, "sensor": [ { "id": 1, "name": "DS18B20", "type": "temperature", "date_created": "2020-06-26T16:30:28.657804Z", "value": 123.0, "index":

How to add data to nested serializers?

大城市里の小女人 提交于 2020-07-28 04:44:12
问题 I'm trying to add data to my database by rest API and I have some problems with adding the data. So basically I have added this data from the admin page, but I want to add this from my other python by using requests. When I'm sending post request it shows me that it has been added, but sensor array is empty [ { "id": 1, "name": "Stacja 1", "delay_time": 123, "sensor": [ { "id": 1, "name": "DS18B20", "type": "temperature", "date_created": "2020-06-26T16:30:28.657804Z", "value": 123.0, "index":

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

PyCharm Debugger Lines Are Out Of Sync With Reality

霸气de小男生 提交于 2020-07-21 04:14:10
问题 I'm using Django Rest Framework 3.5.4 and Pycharm Professional 2016.3.1. Incidentally, I have PyCharm configured to use a virtualenv inside a local vagrant box. When I step through the DRF code with the debugger on, I can see that it is stepping through blank lines, and the variables in the debugger don't match those in scope (pictured here is rest_framework.response.Response.rendered_content() ): Here's another example that shows how variables in scope in the debugger don't match the single

PyCharm Debugger Lines Are Out Of Sync With Reality

放肆的年华 提交于 2020-07-21 04:14:08
问题 I'm using Django Rest Framework 3.5.4 and Pycharm Professional 2016.3.1. Incidentally, I have PyCharm configured to use a virtualenv inside a local vagrant box. When I step through the DRF code with the debugger on, I can see that it is stepping through blank lines, and the variables in the debugger don't match those in scope (pictured here is rest_framework.response.Response.rendered_content() ): Here's another example that shows how variables in scope in the debugger don't match the single

Bulk delete Django by ids

天涯浪子 提交于 2020-07-20 04:51:22
问题 I writing a project using Django REST Framework, Django and Postgres as a database. I want to bulk delete in one query. So, it is possible to do without writing a query using pure SQL? There is an example, but the count of executet query equal length of a list of ids (for example, if in delete_ids 2 ids, Django will execute 2 queries): delete_ids = [...] MyModel.objects.filter(id__in=delete_ids).delete() 回答1: Not possible using the filter and delete together using raw sql query. https://docs

valid UUID is not a valid UUID

冷暖自知 提交于 2020-07-18 04:39:58
问题 I have a really weird problem were I'm getting that a valid UUID is not a valid UUID, for example: 'fd31b6b5-325d-4b65-b496-d7e4d16c8a93' is not a valid UUID. File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py" in get_db_prep_value 2371. value = uuid.UUID(value) File "/usr/lib64/python3.4/uuid.py" in __init__ 134. hex = hex.replace('urn:', '').replace('uuid:', '') During handling of the above exception ('UUID' object has no attribute 'replace'), another