I am looking for a proper way to be able to pass a manually created list of objects to Wagtail API.
The list is coming from an imported function which simply generates the following list.
List (not a queryset or model instance)
data = [ {"id":"1","name":"John"}, {"id":"2","name":"Jack"}, {"id":"3","name":"Jim"} ]
I might have done it wrong but I have added a simple property of no type in the model:
from external_source import generate_data
class MyModel(BaseContentPage):
...
data = generate_data()
...
api_fields = (
...
+ [
APIField(data)
]
)
Create SerializerMethodField in your Serializer Class:
and then create a function get_some_list(self):