mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 20:28:46 -05:00
posprocessing hook for DRF
This commit is contained in:
11
cookbook/helper/drf_spectacular_hooks.py
Normal file
11
cookbook/helper/drf_spectacular_hooks.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
|
||||
|
||||
def custom_postprocessing_hook(result, generator, request, public):
|
||||
for c in result['components']['schemas'].keys():
|
||||
if 'properties' in result['components']['schemas'][c] and 'id' in result['components']['schemas'][c]['properties']:
|
||||
print('setting non read only for ', c)
|
||||
result['components']['schemas'][c]['properties']['id']['readOnly'] = False
|
||||
if 'required' in result['components']['schemas'][c] and 'id' in result['components']['schemas'][c]['required']:
|
||||
result['components']['schemas'][c]['required'].remove('id')
|
||||
return result
|
||||
@@ -952,7 +952,12 @@ class RecipeOverviewSerializer(RecipeBaseSerializer):
|
||||
'waiting_time', 'created_by', 'created_at', 'updated_at',
|
||||
'internal', 'servings', 'servings_text', 'rating', 'last_cooked', 'new', 'recent'
|
||||
)
|
||||
read_only_fields = ['id', 'name', 'description', 'image', 'keywords', 'working_time',
|
||||
# TODO having these readonly fields makes "RecipeOverview.ts" (API Client) not generate the RecipeOverviewToJSON second else block which leads to errors when using the api
|
||||
# TODO find a solution (maybe trough a custom schema) to have these fields readonly (to save performance) and generate a proper client (two serializers would probably do the trick)
|
||||
# read_only_fields = ['id', 'name', 'description', 'image', 'keywords', 'working_time',
|
||||
# 'waiting_time', 'created_by', 'created_at', 'updated_at',
|
||||
# 'internal', 'servings', 'servings_text', 'rating', 'last_cooked', 'new', 'recent']
|
||||
read_only_fields = ['image', 'keywords', 'working_time',
|
||||
'waiting_time', 'created_by', 'created_at', 'updated_at',
|
||||
'internal', 'servings', 'servings_text', 'rating', 'last_cooked', 'new', 'recent']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user