https://remoteindian.com/ logo
#random
Title
# random
h

hundreds-photographer-33216

08/26/2022, 10:08 AM
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

colossal-lawyer-41920

08/26/2022, 12:20 PM
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

wide-twilight-82330

08/26/2022, 4:09 PM
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

hundreds-photographer-33216

08/26/2022, 7:36 PM
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

bumpy-yacht-16235

08/28/2022, 12:35 PM
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
2 Views