perf: 修改 manager

pull/10327/head
ibuler 2023-04-24 19:03:44 +08:00
parent 3cdb81cf4a
commit c824ae4478
1 changed files with 7 additions and 14 deletions

View File

@ -356,10 +356,6 @@ class JSONManyToManyDescriptor:
else: else:
manager = instance._related_manager_cache[self.field.name] manager = instance._related_manager_cache[self.field.name]
# if self.field.name == 'users':
# print(">>> Call __set__: ", manager, value)
# print("Field: ", self.field.name)
# print("Instance: ", instance.__dict__)
if isinstance(value, RelatedManager): if isinstance(value, RelatedManager):
value = value.value value = value.value
manager.set(value) manager.set(value)
@ -379,19 +375,16 @@ class JSONManyToManyField(models.JSONField):
kwargs['to'] = self.to kwargs['to'] = self.to
return name, path, args, kwargs return name, path, args, kwargs
def get_db_prep_value(self, value, connection, prepared=False): def get_db_prep_value(self, manager, connection, prepared=False):
if value is None: if manager is None:
return None return None
v = value.value v = manager.value
print("$$$ Get_db_prep_value: ", self.to, value, v)
print("Value field: ", value.__dict__)
return json.dumps(v) return json.dumps(v)
def get_prep_value(self, value): def get_prep_value(self, manager):
if value is None: if manager is None:
return value return manager
v = value.field.value v = manager.value
print("get_prep_value: ", value, v)
return json.dumps(v) return json.dumps(v)
def validate(self, value, model_instance): def validate(self, value, model_instance):