Skip to content

Technical: Create table, api, and tests

Ethan-Strominger edited this page Jan 13, 2024 · 6 revisions

Once you have the model name and the field, follow the instructions below.

  1. Create model. Look for model TopicArea for an example.
  • Modify kb/model.py
  • Run from terminal
python manage.py makemigrations
python manage.py migration
  1. Add code for displaying on screen. You can manually edit kb/api/admin.py using TopicArea as an example or run
python manage.py autogenerate_admin <ModelName>
  1. Verify you can add and list asset types from admin screen (http://

  2. Add serializer to specify which fields are returned by the serializer. Standard kb apisreturn all fields except created_date and updated_date. You can manually edit kb/api/serializers.py using TopicArea as an example or run

python manage.py autogenerate_serializers <ModelName>
  1. Add views, decorate with @extended_schema, and specify serializer from previous step. You can manually edit kb/api/views.py using TopicArea as an example or run
python manage.py autogenerate_views <ModelName>
  1. Add url to urls.py, decorate with @extended_schema, and specify serializer from previous step. You can manually edit kb/api/views.py using TopicArea as an example or run
python manage.py autogenerate_urls <ModelName>
  1. Manually verify the API is working using Swagger documentation by navigating to http://localhost:8001/api/schema/swagger-ui/ and selecting the API from the list of APIs.

  2. Manually verify the schema using http://localhost:8001/api/schema/swagger-ui/ and navigating to the schema section.

  3. Verify URL http://localhost:8001/api/schema/ downloads or displays a schema and that the schema includes the API.

  4. Add tests. You can manually edit the files specified below using TopicArea as an example or run

python manage.py autogenerate_tests <ModelName>
  1. To run tests, from terminal type:
pytest