mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-18 00:08:31 +00:00
perf: 优化 json m2m field
This commit is contained in:
@@ -220,8 +220,17 @@ class PhoneField(serializers.CharField):
|
||||
|
||||
|
||||
class JSONManyToManyField(serializers.JSONField):
|
||||
def to_representation(self, value):
|
||||
return value.value
|
||||
def to_representation(self, manager):
|
||||
if manager is None:
|
||||
return manager
|
||||
value = manager.value
|
||||
if not isinstance(value, dict):
|
||||
return {"type": "ids", "ids": []}
|
||||
if value.get("type") == "ids":
|
||||
valid_ids = manager.all().values_list("id", flat=True)
|
||||
valid_ids = [str(i) for i in valid_ids]
|
||||
return {"type": "ids", "ids": valid_ids}
|
||||
return value
|
||||
|
||||
def to_internal_value(self, data):
|
||||
if not data:
|
||||
|
Reference in New Issue
Block a user