예제 #1
0
파일: writer.py 프로젝트: Hollow-user/qr
 def register_serializer(cls, type_, serializer):
     Serializer.register(type_, serializer)
예제 #2
0
파일: writer.py 프로젝트: GeyseR/django
 def register_serializer(cls, type_, serializer):
     Serializer.register(type_, serializer)
예제 #3
0
    def ready(self):
        from .management.commands.lib.operators import Variable
        from .management.commands.lib.serializer import VariableSerializer

        Serializer.register(Variable, VariableSerializer)
예제 #4
0
from django.db.migrations.serializer import BaseSerializer, serializer_factory, Serializer

from .enums import Choices


class ChoicesSerializer(BaseSerializer):
    """
    Custom serializer for enumerations.

    Code lifted from https://github.com/django/django/blob/master/django/db/migrations/serializer.py.
    """
    def serialize(self):
        return serializer_factory(self.value.value).serialize()


# Register the custom serializer
Serializer.register(Choices, ChoicesSerializer)
# It is important that the ChoicesSerializer appears before the EnumSerializer in the registry
# The registry is an ordered dict in Django 2.2, so all we can do is move it to the beginning
Serializer._registry.move_to_end(Choices, last=False)