mirror of
https://github.com/carrotquest/django-clickhouse.git
synced 2024-11-15 05:46:41 +03:00
Changed model_to_dict, so it doesn't require _meta attribute,
if fields are given
This commit is contained in:
parent
8d31209a58
commit
90ec66f380
|
@ -3,7 +3,7 @@ from typing import NamedTuple
|
||||||
import pytz
|
import pytz
|
||||||
from django.db.models import Model as DjangoModel
|
from django.db.models import Model as DjangoModel
|
||||||
|
|
||||||
from django_clickhouse.utils import model_to_dict
|
from .utils import model_to_dict
|
||||||
|
|
||||||
|
|
||||||
class Django2ClickHouseModelSerializer:
|
class Django2ClickHouseModelSerializer:
|
||||||
|
|
|
@ -116,8 +116,9 @@ def model_to_dict(instance, fields=None, exclude_fields=None):
|
||||||
"""
|
"""
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
opts = instance._meta
|
if not fields:
|
||||||
fields = fields or {f.name for f in chain(opts.concrete_fields, opts.private_fields, opts.many_to_many)}
|
opts = instance._meta
|
||||||
|
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()):
|
for name in set(fields) - set(exclude_fields or set()):
|
||||||
val = getattr(instance, name, None)
|
val = getattr(instance, name, None)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user