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)]
Till now, we had to convert many to many field to an queryset
Automatically, validate Django's all fields with
QueryList
. But aQueryList
converter would be easy.