Taking you API to the next level
Django Rest Framework
$whoami Carlos Martínez Backend Developer en twitter @carlosmart626 github carlosmart626 https://carlosmart.co
$whoami Colombia @carlosmart626
$whoami @carlosmart626
5 Minute API
Ticket Store Users Events Promotors Tickets @carlosmart626
Display different data based on context Getting better performance Filtering information Permissions How to render results in different formats? @carlosmart626
Reuse Serializers
How to reuse your serializers to show different representations? Create multiple ModelSerializer with different selected fields @carlosmart626
How to reuse your serializers to show different representations? DynamicSerializers! @carlosmart626
Dynamic Serializers Use DynamicSerializer instead ModelSerializer @carlosmart626
Dynamic Serializers Use DynamicSerializer instead ModelSerializer @carlosmart626
Dynamic Serializers @carlosmart626
Dynamic Serializers Now you can reuse the serializer easier @carlosmart626
Getting better performance @carlosmart626
Prefetch Keep in mind the number of queries @carlosmart626
Prefetch Select Related Follow foreign key relationships by getting a single but more complex query @carlosmart626
Prefetch Select Related Follow foreign key relationships by getting a single but more complex query django/querysets/#select-related @carlosmart626
Prefetch Select Related Follow foreign key relationships by getting a single but more complex query @carlosmart626
Prefetch Query @carlosmart626
Prefetch Query @carlosmart626
Prefetch Prefetch Related Great to many-to-many and many-to-one @carlosmart626
Prefetch Prefetch Related Similar to ‘select_related’ creates a more queries executed to get the related data @carlosmart626
Prefetch Prefetch Related Similar to ‘select_related’ creates a more queries executed to get the related data @carlosmart626
Prefetch Prefetch Object This object can be used to customize the ‘prefetch_related’ operations django/querysets/#prefetch-objects @carlosmart626
Prefetch Prefetch Object This object can be used to customize the ‘prefetch_related’ operations django/querysets/#prefetch-objects @carlosmart626
Filtering
django-url-filter Let’s filter your endpoints in a better way @carlosmart626
django-url-filter Add filter_backends and select your filter fields @carlosmart626
django-url-filter Add filter_backends and select your filter fields @carlosmart626
django-url-filter @carlosmart626
django-url-filter ModelFilterSet @carlosmart626
Cache @carlosmart626
Cache View example Django Cache in DRF ModelViewSets @carlosmart626
Cache View example Django Cache in DRF ModelViewSets @carlosmart626
Cache View example Django Cache in DRF ModelViewSets @carlosmart626
Cache Key invalidation DON’T FORGET TO INVALIDATE CACHE @carlosmart626
django-cacheops Cacheops let’s you cache the ORM @carlosmart626
django-cacheops Cacheops can work using redis @carlosmart626
django-cacheops Cacheops common configurations Default time out Apps/Models to cache with operations and time settings @carlosmart626
django-cacheops Cacheops common configurations Default time out Apps/Models to cache with operations and time settings @carlosmart626
django-cacheops Cacheops provides different ways to cache ORM operations It’s automatic! But, you can define a queryset and append cache() at the end to cache the ORM results. https://github.com/Suor/django-cacheops @carlosmart626
django-cacheops Cacheops provides different ways to cache ORM operations It’s automatic! But, you can define a queryset and append cache() at the end to cache the ORM results. https://github.com/Suor/django-cacheops @carlosmart626
Permissions
Permissions DRYPermissions You can define global, object and action permissions in each one of your models. @carlosmart626
DRYPermissions @carlosmart626
DRYPermissions Using DRYPermission in a ViewSet Add to permission_classes DRYPermissions @carlosmart626
DRYPermissions Using DRYPermission in a ViewSet Add to permission_classes DRYPermissions @carlosmart626
DRYPermissions Global Permissions You have access to the request so you can get information about the user @carlosmart626
DRYPermissions Object Permissions You can define object permissions and you get both request and the object to make validations @carlosmart626
DRYPermissions Field/Action Permissions You can define logic to access to fields and actions within a model viewset @carlosmart626
DRYPermissions Custom permission class @carlosmart626
DRYPermissions Custom permission class @carlosmart626
DRYPermissions Custom permission class @carlosmart626
DRYPermissions DRYPermission on APIView Outside a Viewset you need to add to the serializer a context https://github.com/dbkaplan/dry-rest-permissions @carlosmart626
DRYPermissions DRYPermission on APIView Outside a Viewset you need to add to the serializer a context https://github.com/dbkaplan/dry-rest-permissions @carlosmart626
Rederers
XLSXRenderer Drf-renderer-xlsx This package let you export excel files directly from your api instead to get a son you can get a xlsx file with all the filters you already define at the URL @carlosmart626
XLSXRenderer It’s very simple to use @carlosmart626
XLSXRenderer It’s very simple to use @carlosmart626
Code https://github.com/CarlosMart626/ djangocon-2019
Demo 爛
Thank you @carlosmart626
Recommend
More recommend