Please enable JavaScript.
Coggle requires JavaScript to display documents.
ADVANCED_API_1 - Coggle Diagram
ADVANCED_API_1
VIEWSETS
Import
Viewsets
<Type>ModelViewSet
ModelNameViewset
Extends
<Type>ModelViewSet
Methods
GetQueryset
Set
Basename
Router
GetSerializerClass
GetSerializerContext
Attributes
Queryset
SerializerClass
Replace
Delete
Destroy
Instance
Already
Retrieved
Check
RelatedModel
Objects
Filter
modelObj_id
kwargs['pk']
Count()
'> 0
Return
Error
Success
SuperCall
CLASS-VIEWS
Import
view
APIView
ModelList
Extends
APIView
Methods
Get
Post
Arg
Self
Request
[pk]
Url
Views
ModelList
As_view()
GENERIC-VIEWS
ModelMixins
Create
List
Retrieve
Update
Destroy
Customizing
Overriding
Delete
Get
Post
Put
Combines
Mixins
GenericAPIView
Using
Import
Generics
<Type>APIView
ModelList
Extends
<Type>APIView
Attributes
Queryset
SerializerClass
Methods
GetQueryset
GetSerializerClass
GetSerializerContext
Access
Self.Request
NESTED_ROUTERS
Install
DrfNestedRouters
Urls.py
Import
Routers
DefaultRouter
NestedDefaultRouter
RestFrameworkNested
Declare
Parent
Router
ChildRouter
NestedDefaultRouter()
ParentRouter
'ParentPrefix'
Lookup
Parent
Register
'ChildPrefix'
Viewset
Basename
Parent-Childprefix
Urlpatterns
ChildRouter.Urls
Append
ChildViewSet
GetSerializerContext
Return
Dict
ParentPk
Self.Kwargs['parent_pk']
GetQueryset
Return
ChildModel
Objects
Filter()
ParentId
Self.Kwargs['parent_pk']
ChildSerializer
Override
Create
ParentId
Self.Context['ParentPk']
Return
ChildModel
Create
ParentId
**ValidatedData
STEPS
Build
Model
Create
Model
Migration
Apply
Migration
API
Create
Serializer
View
Register
Route
ROUTERS
Import
Routers
SimpleRouter
DefaultRouter
ApiRoot
model.json
Using
RouterObj
SimpleRouter()
Register()
ModelNameS
views.ModelNameViewSet
Append
Urlpatterns
RouterObj.urls
Path()
EmptyStr
Include(router.urls)