A Django project with samples code strictly DRY (DON'T REPEAT YOURSELF)
CRUD are operations that most project implements. Django Rest Framework can be used for this purpose, to develop Rest API Endpoint.
-
- viewsets.ModelViewSet Use this class if you want enable to consume all CRUD operations
- viewsets.GenericViewSet Use these classes to enable only some CRUD operations.
-
- viewsets.ViewSet Use this class if you want enable to consume all CRUD operations
-
- Simple queries
- Advanced queries
-
- Validations Model layer
- Write Validations logic into Model.clean() that check model fields data integrity. If call Model.save() from Model.Form, Model.Serializer, ModelAdmin object MUST BE validated before saved into db.
- Warnings
- pre_save_full_clean_handler model.full_clean() is not called by default when invoke Model.save() method ISSUE
- django_error_handler Improve conversion from exceptions.ValidationError() to serializer.ValidationError()
- Validations View layer
- Write Validations logic into ModelSerializer.validate() and ModelForms.clean() YES NOT DRY π that check model fields data integrity using view parameters as request, that aren't accessible into Model class.
- Single row
- Nested ForeignKey
- Validations Model layer
-
- Warnings
- UpdateModelQuerySet Add this Mixing for prevent update not call Model.save() method. Unfortunately, there isnβt a workaround when creating or updating objects in bulk, since none of save(), pre_save, and post_save are called.
- Warnings
-
- Validations Model layer
- Write Validations logic into signals.pre_delete
- Validations View layer
- Write Validations logic into viewsets.destroy() YES NOT DRY π that check model fields data integrity using view parameters as request, that aren't accessible into Model/Signal class.
- Validations Model layer
Utils folder can be used to store utils method/class
- Create for each plugin, one utils file
Client_PageNumberPagination class can be used to enable client custom pagination size.
<url>?page_size=20
Get 20 items at time, get page=1 (default)<url>?page=2
Get the page number, get page_size=10 (default)<url>?page_size=20&page=2
Get 20 items at time, get page=2
Debug_BrowsableAPIRenderer class can be used to use browsable api ONLY into DEBUG MODE.