Как создать в django свой DEFAULT_AUTO_FIELD с uuid4?

DEFAULT_AUTO_FIELD = 'core.custom_auto_field.UID4AutoField'


from django.db.models.fields import AutoFieldMixin, UUIDField

from uuid import uuid4


class UID4AutoField(AutoFieldMixin, UUIDField):
    def get_internal_type(self):
        return 'UID4AutoField'

    def rel_db_type(self, connection):
        return UUIDField().db_type(connection=connection)
Вернуться на верх