allowAction Approve assignmentType Single User userEntity id mailtoalokgetmaxlistenerscom value Alok timeLimit 5 timeLimitType Hour
To save this JSON data in a Django model field of type JSONField in MySQL, follow these steps:
- Import the JSONField from django.db.models.fields.json:
from django.db import models
from django.db.models.fields.json import JSONField
- Define your model with a JSONField:
class ApprovalRequest(models.Model):
request_data = JSONField()
- Create a new instance of your model and set the request_data field to your JSON data:
import json
data = {
"allowAction": [
"Approve"
],
"assignmentType": "Single User",
"userEntity": [
{
"id": "mailto:alok@getmaxlisteners.com",
"value": "Alok"
}
],
"timeLimit": "5",
"timeLimitType": "Hour",
"completionPolicy": "Majority of approvers"
}
approval_request = ApprovalRequest.objects.create(request_data=json.dumps(data))
- To retrieve the JSON data from the database, simply access the request_data field:
approval_request = ApprovalRequest.objects.get(id=1)
data = json.loads(approval_request.request_data)
原文地址: https://www.cveoy.top/t/topic/6wm 著作权归作者所有。请勿转载和采集!