first ugly version of values and values_list - to refactor and check with m2m

This commit is contained in:
collerek
2021-06-04 18:21:16 +02:00
parent 7b92884f39
commit b1b3d5cd92
5 changed files with 313 additions and 4 deletions

View File

@ -87,6 +87,17 @@ class ExcludableItems:
new_excludable.items[key] = value.get_copy()
return new_excludable
def include_entry_count(self) -> int:
"""
Returns count of include items inside
"""
count = 0
if not self.items:
return count
for key in self.items.keys():
count += len(self.items[key].include)
return count
def get(self, model_cls: Type["Model"], alias: str = "") -> Excludable:
"""
Return Excludable for given model and alias.

View File

@ -86,6 +86,7 @@ class ExcludableMixin(RelationMixin):
excludable: ExcludableItems,
alias: str = "",
use_alias: bool = False,
add_pk_columns: bool = True,
) -> List[str]:
"""
Returns list of aliases or field names for given model.
@ -96,6 +97,8 @@ class ExcludableMixin(RelationMixin):
Primary key field is always added and cannot be excluded (will be added anyway).
:param add_pk_columns: flag if add primary key - always yes if ormar parses data
:type add_pk_columns: bool
:param alias: relation prefix
:type alias: str
:param excludable: structure of fields to include and exclude
@ -130,9 +133,10 @@ class ExcludableMixin(RelationMixin):
]
# always has to return pk column for ormar to work
columns = cls._populate_pk_column(
model=model, columns=columns, use_alias=use_alias
)
if add_pk_columns:
columns = cls._populate_pk_column(
model=model, columns=columns, use_alias=use_alias
)
return columns