Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.urls import reverse
- from rest_framework import serializers
- from misc.views.generic_serializer import GenericSerializer, GenericSerializerField
- from users.models import UserProperty
- class UserPropertySerializer(GenericSerializer):
- """
- Отвечает за сериализацию данных модели UserProperty (табличное представление), оправляемых в ответе на запрос.
- """
- readonly_field = ['user_field', 'user_property']
- mandatory_fields = ['user_field', 'user_property']
- create_field = ['transfer_date_field', 'declared_value_field', 'return_date_field', 'user_property_field', 'user_field',]
- id_field = GenericSerializerField(model_field_name='id')
- user_field = GenericSerializerField(
- model_field_name='user_id',
- model_field_verbose='user__get_full_name',
- field_verbose_is_method=True,
- )
- user_property_field = GenericSerializerField(
- model_field_name='property_id',
- field_verbose_is_method=True,
- )
- transfer_date_field = GenericSerializerField(model_field_name="transfer_date_field")
- declared_value_field = GenericSerializerField('declared_value_field')
- return_date_field = GenericSerializerField(model_field_name='return_date_field')
- delete_btn_field = serializers.SerializerMethodField()
- fields_information = {
- 'id_field': GenericSerializer.get_field_information(
- model_name='id',
- field_verbose='ID',
- ),
- 'user_field' : GenericSerializerField.get_field_information(
- model_name='user',
- field_verbose='Ответственный сотрудник по возврату данных',
- field_verbose_is_method=True,
- ),
- 'user_property_field' : GenericSerializerField.get_field_information(
- model_name='property',
- field_verbose='Имущество выданное сотруднику',
- ),
- 'transfer_date_field' : GenericSerializerField.get_field_information(
- model_name="transfer_date_field",
- field_verbose='Дата передачи',
- ),
- 'declared_value_field' : GenericSerializerField.get_field_information(
- model_name='declared_value_field',
- field_verbose='Количество',
- ),
- 'return_date_field' : GenericSerializerField.get_field_information(
- model_name='return_date_field',
- field_verbose='Дата возврата',
- ),
- 'delete_btn_field': GenericSerializer.get_field_information(),
- }
- class Meta:
- model = UserProperty
- depth = 1
- fields = [
- 'id_field',
- 'transfer_date',
- 'declared_value',
- 'return_date',
- 'user_property',
- 'user',
- # 'project',
- ]
Add Comment
Please, Sign In to add comment