django-eav2/eav/logic/entity_pk.py
Mike a98766fc55
Add support for Entity models with UUID as a primary key. (#89)
* chore: fix repo links

* style: flake8 format models.Value

* test: add test for an entity with uuid pk

* feat: support entity models with uuid as pk

* test: check Value repr and str methods
2021-10-22 15:36:17 -07:00

12 lines
371 B
Python

from django.db.models.fields import UUIDField
def get_entity_pk_type(entity_cls) -> str:
"""Returns the entity PK type to use.
These values map to `models.Value` as potential fields to use to relate
to the proper entity via the correct PK type.
"""
if isinstance(entity_cls._meta.pk, UUIDField):
return 'entity_uuid'
return 'entity_id'