If you are a noob in Django or Django REST Framework (DRF),
it's pretty hard to find (complete) example about providing REST API for system with (sql relationship) foreign key on its database.
this example on SO is quite straigth forward and complete, about DRF with foreignkey.
ya, you also get django.test.Client information as a bonus. nice!
mostly my problem is about reverse relationship .
I used to use Jinja2 for templating, and it support Math calculation .
Now when try Django template, I can't calculate simple math (only add available via builtin filter), so I have to implement filter by myself, or using django-mathfilters .
What do you need is only install mathfilters with pip then add mathfilters to INSTALLED_APPS on your settings.
There is a rule in Python programming called "it is Easier to Ask for Forgiveness than for Permission" (in short: EAFP). It means that you should catch exceptions instead of checking values for validity.
How to serialize model to JSON on Django?
Django has serializers module on it's core.
from django.core import serializers from myproject.myapp import models data = serializers.serialize("json", models.MyModel.objects.all())
really simple :)