Hey folks, is there anyone experienced in django? ...
# random
h
Hey folks, is there anyone experienced in django? I am new to the framework and I am trying to make simple REST apis using django rest framework. I am confused between functional, class views and using APIView vs ModelViewsets. I can’t find a good reference that explains setting these up for a simple project that has few foreign keys in the models. I would love if someone can chat/point to a good reference on this.
c
DRF documentation is the way to go. https://www.django-rest-framework.org/
You can follow the quickstart guide and that will clear your concepts about viewsets. model viewsets and how to design model with FK
w
APIView is a generic view ModelView is when you have a model and you want CRUD for that while writing only some parts of it ModelView inherits from the APIView DRF docs are the best place to start
h
Thanks! I was able to get it going. Where I was stuck --- I had a foreign key in a model and I wanted my Class based viewset to allow POST request with only valid foreign keys (keys that are already present in refrenced model).
b
wanted my Class based viewset to allow POST request with only valid foreign keys
Model Serializers can help you with this. https://www.django-rest-framework.org/api-guide/relations/#the-queryset-argument