Bishwas-py / djapy

No bullshit, Django Rest API Framework
https://djapy.io
59 stars 3 forks source link

QuerySet to QueryList easy validation #22

Closed Bishwas-py closed 3 months ago

Bishwas-py commented 3 months ago

Till now, we had to convert many to many field to an queryset

    @field_validator('feedback_options', mode='before')
    def validate_feedback_options(cls, feedback_options: QuerySet[FeedbackOption]):
        return [i for i in feedback_options.all()]

Automatically, validate Django's all fields with QueryList. But a QueryList converter would be easy.

def query_list_validator(value):
    """
    Validator to ensure the Django model queryset is not empty.
    """
    return value.all()

QueryList = Annotated[List[G_TYPE], BeforeValidator(query_list_validator)]