We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修改了 Serializer 文件的data_inspect函数。 代码如下,加了一个rel属性判断。 由于代码没有注释,一时之间也找不到具体问题在哪,所以胡乱改了一下,希望作者看到问题后进行修复。
Serializer
data_inspect
rel
def data_inspect(self, data, extra=None): if isinstance(data, (QuerySet, Page, list)): convert_data = [] if extra: for i, obj in enumerate(data): convert_data.append(self.data_inspect(obj, extra.get( **{self.through_fields[0]: obj, self.through_fields[1]: self.source_field}))) else: for obj in data: convert_data.append(self.data_inspect(obj)) return convert_data elif isinstance(data, models.Model): obj_dict = {} concrete_model = data._meta.concrete_model for field in concrete_model._meta.local_fields: # 检查 field 是否存在 rel 这个属性,为'AutoField' object has no attribute 'rel'错误填坑 if hasattr(field, 'rel'): if field.rel is None: if self.check_attr(field.name) and hasattr(data, field.name): obj_dict[field.name] = self.data_inspect(getattr(data, field.name)) else: if self.check_attr(field.name) and self.foreign: obj_dict[field.name] = self.data_inspect(getattr(data, field.name)) else: if self.check_attr(field.name) and hasattr(data, field.name): obj_dict[field.name] = self.data_inspect(getattr(data, field.name)) for field in concrete_model._meta.many_to_many: if self.check_attr(field.name) and self.many: obj_dict[field.name] = self.data_inspect(getattr(data, field.name)) for k, v in data.__dict__.items(): if not str(k).startswith('_') and k not in obj_dict.keys() and self.check_attr(k): obj_dict[k] = self.data_inspect(v) if extra: for field in extra._meta.concrete_model._meta.local_fields: if field.name not in obj_dict.keys() and field.name not in self.through_fields: if field.rel is None: if self.check_attr(field.name) and hasattr(extra, field.name): obj_dict[field.name] = self.data_inspect(getattr(extra, field.name)) else: if self.check_attr(field.name) and self.foreign: obj_dict[field.name] = self.data_inspect(getattr(extra, field.name)) return obj_dict elif isinstance(data, manager.Manager): through_list = data.through._meta.concrete_model._meta.local_fields through_data = data.through._default_manager self.through_fields = [data.target_field.name, data.source_field.name] self.source_field = data.instance if len(through_list) > 3 and self.through: return self.data_inspect(data.all(), through_data) else: return self.data_inspect(data.all()) elif isinstance(data, (datetime.datetime, datetime.date, datetime.time)): return self.time_func(data) elif isinstance(data, (ImageFieldFile, FileField)): return data.url if data.url else data.path elif isinstance(data, Decimal): return float(data) elif isinstance(data, dict): obj_dict = {} if self._dict_check: for k, v in data.items(): obj_dict[k] = self.data_inspect(v) else: for k, v in data.items(): if self.check_attr(k): obj_dict[k] = self.data_inspect(v) return obj_dict elif isinstance(data, (str, bool, float, int)): return data else: return None
The text was updated successfully, but these errors were encountered:
我的fork版本中已经修复了这个问题:https://github.com/Deali-Axy/django-simple-serializer
Sorry, something went wrong.
我的叉子版本中已经修复了这个问题:https : //github.com/Deali-Axy/django-simple-serializer
如何使用你这个临时版本呢,pip 无法找到
我的叉子版本中已经修复了这个问题:https : //github.com/Deali-Axy/django-simple-serializer 如何使用你这个临时版本呢,pip 无法找到
clone下来直接import就行啦
No branches or pull requests
修改了
Serializer
文件的data_inspect
函数。代码如下,加了一个
rel
属性判断。由于代码没有注释,一时之间也找不到具体问题在哪,所以胡乱改了一下,希望作者看到问题后进行修复。
The text was updated successfully, but these errors were encountered: