Skip to content

Typical workflow

Ivan Santos edited this page Mar 21, 2019 · 5 revisions

URL

If you want to create a new piece of the system, first of all I would create the new API endpoint which you will be using, inside the urls.py file.

Bill is the name of the view which will take care of that url path. name='bill' is related to some use inside html templates, I read it is a good practise so that's why. link

path('api/v1/bill/', Bill ,name='bill')

Model

Then create your model inside datame application, official documentation about model field types.

View

Needs to be reviewed

@csrf_exempt

Don't forget to import your models

from .models import Offer_model

Documentation about how to create a new object or how to retrieve new objects from database, link

I use python3 manage.py shell as recommended on the tutorial.

Use JsonResponse({...}) for sending a json from server to client.

Testing

Postman is great for testing endpoints, you can test GET or POST requests (And any other HTTP request).

An example of POST would be

http://127.0.0.1:8000/api/v1/offer/ as url

HEADERS key=Content-type and value=application/json

BODY, mark form-data

img

Names in key will be used in your view to retrieve each option.

Check inside django admin

Add in your project admin.py the next line related to the model you would like to view from the django admin panel.

Don't forget to import your models from .models import Offer_model

admin.site.register(Offer_model)

Create a superuser account and then you will have it available inside http://localhost:8000/admin/

Clone this wiki locally