Mochinov

Untitled

Apr 8th, 2022 (edited)
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.92 KB | None | 0 0
  1. from django.urls import reverse
  2. from rest_framework import serializers
  3.  
  4. from misc.views.generic_serializer import GenericSerializer, GenericSerializerField
  5. from users.models import ConnectingUserToAccess
  6.  
  7.  
  8. class ConnectingUserToAccessSerializer(GenericSerializer):
  9.     """
  10.    Отвечает за сериализацию данных модели ConnectingUserToAccessSerializer
  11.    (табличное представление), оправляемых в ответе на запрос.
  12.    """
  13.  
  14.     readonly_field = ['user_field',  'user_access_field']
  15.     mandatory_fields = ['user_field', 'user_access_field']
  16.     create_field = ['user_field', 'user_access_field', 'transfer_date_field', 'return_date_field', 'comment_field',]
  17.  
  18.     id_field = GenericSerializerField(model_field_name='id')
  19.     user_field = GenericSerializerField(
  20.         model_field_name='user_id',
  21.         model_field_verbose='user__get_full_name',
  22.         field_verbose_is_method=True,
  23.     )
  24.     user_access_field = GenericSerializerField(
  25.         model_field_name='user_access',
  26.         field_verbose_is_method=True,
  27.     )
  28.     transfer_date_field = GenericSerializerField(model_field_name="transfer_date")
  29.     return_date_field = GenericSerializerField(model_field_name='return_date')
  30.     comment_field = GenericSerializerField(model_field_name='comment_field')
  31.     delete_btn_field = serializers.SerializerMethodField()
  32.  
  33.     fields_information = {
  34.         'id_field': GenericSerializer.get_field_information(
  35.             model_name='id',
  36.             field_verbose='ID',
  37.         ),
  38.         'user_field' : GenericSerializerField.get_field_information(
  39.             model_name='user',
  40.             field_verbose='Ответственный сотрудник по возврату данных',
  41.             field_verbose_is_method=True,
  42.         ),
  43.         'user_access_field' : GenericSerializerField.get_field_information(
  44.             model_name='user_access',
  45.             field_verbose='Доступ выданный сотруднику',
  46.         ),
  47.         'transfer_date_field' : GenericSerializerField.get_field_information(
  48.             model_name="transfer_date_field",
  49.             field_verbose='Дата передачи',
  50.         ),
  51.         'return_date_field' : GenericSerializerField.get_field_information(
  52.             model_name='declared_value_field',
  53.             field_verbose='Дата возврата',
  54.         ),
  55.         'comment_field' : GenericSerializerField.get_field_information(
  56.             model_name='return_date_field',
  57.             field_verbose='Комментарий',
  58.         ),
  59.         'delete_btn_field': GenericSerializer.get_field_information(),
  60.     }
  61.  
  62.     class Meta:
  63.         model = ConnectingUserToAccess
  64.         depth = 1
  65.         fields = [
  66.             'id_field',
  67.             'transfer_date',
  68.             'return_date',
  69.             'comment',
  70.             'user_access',
  71.             'user',
  72.         ]
  73.  
Add Comment
Please, Sign In to add comment