from {{model_module}} import {{model_name}}
from rest_framework import serializers

{% if "c" in methods %}
class {{model_name}}CreateSerializer(serializers.ModelSerializer):

    {% for user_field in user_fields %}{{user_field}} = serializers.HiddenField(
        default=serializers.CurrentUserDefault(), allow_null=True
    ){% endfor %}

    class Meta:
        model = {{model_name}}
        fields = ({% for field in fields %}{% if field['name'] not in many_to_one_relations %}"{{field['name']}}", {% endif %}{% endfor %})

    {% if "r" in methods %}def to_representation(self, instance):
        return {{model_name}}Serializer().to_representation(instance){% endif %}
{% endif %}
{% if "u" in methods %}
class {{model_name}}UpdateSerializer(serializers.ModelSerializer):
    class Meta:
        model = {{model_name}}
        fields = ({% for field in fields %}{% if field['name'] not in many_to_one_relations %}"{{field['name']}}", {% endif %}{% endfor %})

    {% if "r" in methods %}def to_representation(self, instance):
        return {{model_name}}Serializer().to_representation(instance){% endif %}
{% endif %}
{% if "r" in methods %}
class {{model_name}}Serializer(serializers.ModelSerializer):
    class Meta:
        model = {{model_name}}
        fields = ({% for field in fields %}{% if field['name'] not in many_to_one_relations %}"{{field['name']}}", {% endif %}{% endfor %})
{% endif %}

