Changed model_to_dict, so it doesn't require _meta attribute,

if fields are given
This commit is contained in:
M1ha 2019-02-07 11:41:20 +05:00
parent 8d31209a58
commit 90ec66f380
2 changed files with 4 additions and 3 deletions

View File

@ -3,7 +3,7 @@ from typing import NamedTuple
import pytz
from django.db.models import Model as DjangoModel
from django_clickhouse.utils import model_to_dict
from .utils import model_to_dict
class Django2ClickHouseModelSerializer:

View File

@ -116,8 +116,9 @@ def model_to_dict(instance, fields=None, exclude_fields=None):
"""
data = {}
if not fields:
opts = instance._meta
fields = fields or {f.name for f in chain(opts.concrete_fields, opts.private_fields, opts.many_to_many)}
fields = {f.name for f in chain(opts.concrete_fields, opts.private_fields, opts.many_to_many)}
for name in set(fields) - set(exclude_fields or set()):
val = getattr(instance, name, None)