Generate forms from serializer

Viewed 37

I'm working with React in the front-end with Material-UI, and I would like to auto generate forms based on my serializer's schema.

Usually, the way that CRUD works in the app is by listing the registers, and then give the option to add, edit, or remove registers. So, my idea would be to get the serializer's schema in the listing part of the CRUD and then use it to generate the forms later on. Is there anyway to do this? I'm thinking about maybe creating an npm package to help on it...

Thanks

1 Answers

If you use ModelSerializer and ModelViewSet, you can get the description of the serializer schema sending an OPTIONS request to the endpoint and use it in the front end for building your form based on that information. You even get the choices when the field of the model has them set.

Related