Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/common/field/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
@date:2024/1/11 18:44
@desc:
"""
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -49,15 +51,14 @@ def to_internal_value(self, data):
def to_representation(self, value):
return value


@extend_schema_field(OpenApiTypes.BINARY)
class UploadedImageField(serializers.ImageField):
def __init__(self, **kwargs):
super().__init__(**kwargs)

def to_representation(self, value):
return value


class UploadedFileField(serializers.FileField):
def __init__(self, **kwargs):
super().__init__(**kwargs)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code contains several minor improvements, such as adding docstrings for methods and using proper type annotation with typing. It also imports extends_schema_field from drf_spectacular, which is useful for generating API documentation.

Here are some general comments:

  1. Imports: Ensure that all necessary modules and types are imported at the beginning of the file. The current import statement seems fine.

  2. Type Annotations: While type annotations are beneficial (e.g., def to_representation(self, value): -> Any), they do not significantly enhance readability unless used consistently throughout the application.

  3. Comments: Add detailed comments if additional explanation or context is needed. However, since the description is already provided in a docstring, simple docstrings might be sufficient.

  4. API Documentation: Although you haven't directly specified how these changes affect API documentation generation, extending schematics should help in creating more informative schemas if integrated into an openapi-generator setup.

Overall, maintaining clean code and clear structure while ensuring type hints can improve its maintainability and readiness for larger projects.

Expand Down
Loading