mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2024-11-22 01:26:43 +03:00
Merge pull request #157 from Polishko/correction-proposal
Correct wording in ### Methods section: changed 'Models' to 'Methods'…
This commit is contained in:
commit
b70d21e622
94
README.md
94
README.md
|
@ -15,60 +15,60 @@
|
||||||
- [Why not?](#why-not)
|
- [Why not?](#why-not)
|
||||||
- [Cookie Cutter](#cookie-cutter)
|
- [Cookie Cutter](#cookie-cutter)
|
||||||
- [Models](#models)
|
- [Models](#models)
|
||||||
* [Base model](#base-model)
|
- [Base model](#base-model)
|
||||||
* [Validation - `clean` and `full_clean`](#validation---clean-and-full_clean)
|
- [Validation - `clean` and `full_clean`](#validation---clean-and-full_clean)
|
||||||
* [Validation - constraints](#validation---constraints)
|
- [Validation - constraints](#validation---constraints)
|
||||||
* [Properties](#properties)
|
- [Properties](#properties)
|
||||||
* [Methods](#methods)
|
- [Methods](#methods)
|
||||||
* [Testing](#testing)
|
- [Testing](#testing)
|
||||||
- [Services](#services)
|
- [Services](#services)
|
||||||
* [Example - function-based service](#example---function-based-service)
|
- [Example - function-based service](#example---function-based-service)
|
||||||
* [Example - class-based service](#example---class-based-service)
|
- [Example - class-based service](#example---class-based-service)
|
||||||
* [Naming convention](#naming-convention)
|
- [Naming convention](#naming-convention)
|
||||||
* [Modules](#modules)
|
- [Modules](#modules)
|
||||||
* [Selectors](#selectors)
|
- [Selectors](#selectors)
|
||||||
* [Testing](#testing-1)
|
- [Testing](#testing-1)
|
||||||
- [APIs & Serializers](#apis--serializers)
|
- [APIs & Serializers](#apis--serializers)
|
||||||
* [Naming convention](#naming-convention-1)
|
- [Naming convention](#naming-convention-1)
|
||||||
* [Class-based vs. Function-based](#class-based-vs-function-based)
|
- [Class-based vs. Function-based](#class-based-vs-function-based)
|
||||||
* [List APIs](#list-apis)
|
- [List APIs](#list-apis)
|
||||||
+ [Plain](#plain)
|
- [Plain](#plain)
|
||||||
+ [Filters + Pagination](#filters--pagination)
|
- [Filters + Pagination](#filters--pagination)
|
||||||
* [Detail API](#detail-api)
|
- [Detail API](#detail-api)
|
||||||
* [Create API](#create-api)
|
- [Create API](#create-api)
|
||||||
* [Update API](#update-api)
|
- [Update API](#update-api)
|
||||||
* [Fetching objects](#fetching-objects)
|
- [Fetching objects](#fetching-objects)
|
||||||
* [Nested serializers](#nested-serializers)
|
- [Nested serializers](#nested-serializers)
|
||||||
* [Advanced serialization](#advanced-serialization)
|
- [Advanced serialization](#advanced-serialization)
|
||||||
- [Urls](#urls)
|
- [Urls](#urls)
|
||||||
- [Settings](#settings)
|
- [Settings](#settings)
|
||||||
* [Prefixing environment variables with `DJANGO_`](#prefixing-environment-variables-with-django_)
|
- [Prefixing environment variables with `DJANGO_`](#prefixing-environment-variables-with-django_)
|
||||||
* [Integrations](#integrations)
|
- [Integrations](#integrations)
|
||||||
* [Reading from `.env`](#reading-from-env)
|
- [Reading from `.env`](#reading-from-env)
|
||||||
- [Errors & Exception Handling](#errors--exception-handling)
|
- [Errors & Exception Handling](#errors--exception-handling)
|
||||||
* [How exception handling works (in the context of DRF)](#how-exception-handling-works-in-the-context-of-drf)
|
- [How exception handling works (in the context of DRF)](#how-exception-handling-works-in-the-context-of-drf)
|
||||||
+ [DRF's `ValidationError`](#drfs-validationerror)
|
- [DRF's `ValidationError`](#drfs-validationerror)
|
||||||
+ [Django's `ValidationError`](#djangos-validationerror)
|
- [Django's `ValidationError`](#djangos-validationerror)
|
||||||
* [Describe how your API errors are going to look like.](#describe-how-your-api-errors-are-going-to-look-like)
|
- [Describe how your API errors are going to look like.](#describe-how-your-api-errors-are-going-to-look-like)
|
||||||
* [Know how to change the default exception handling behavior.](#know-how-to-change-the-default-exception-handling-behavior)
|
- [Know how to change the default exception handling behavior.](#know-how-to-change-the-default-exception-handling-behavior)
|
||||||
* [Approach 1 - Use DRF's default exceptions, with very little modifications.](#approach-1---use-drfs-default-exceptions-with-very-little-modifications)
|
- [Approach 1 - Use DRF's default exceptions, with very little modifications.](#approach-1---use-drfs-default-exceptions-with-very-little-modifications)
|
||||||
* [Approach 2 - HackSoft's proposed way](#approach-2---hacksofts-proposed-way)
|
- [Approach 2 - HackSoft's proposed way](#approach-2---hacksofts-proposed-way)
|
||||||
* [More ideas](#more-ideas)
|
- [More ideas](#more-ideas)
|
||||||
- [Testing](#testing-2)
|
- [Testing](#testing-2)
|
||||||
* [Overview](#overview-1)
|
- [Overview](#overview-1)
|
||||||
* [Naming conventions](#naming-conventions)
|
- [Naming conventions](#naming-conventions)
|
||||||
* [Factories](#factories)
|
- [Factories](#factories)
|
||||||
- [Celery](#celery)
|
- [Celery](#celery)
|
||||||
* [The basics](#the-basics)
|
- [The basics](#the-basics)
|
||||||
* [Error handling](#error-handling)
|
- [Error handling](#error-handling)
|
||||||
* [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
* [Structure](#structure)
|
- [Structure](#structure)
|
||||||
* [Periodic Tasks](#periodic-tasks)
|
- [Periodic Tasks](#periodic-tasks)
|
||||||
* [Beyond](#beyond)
|
- [Beyond](#beyond)
|
||||||
- [Cookbook](#cookbook)
|
- [Cookbook](#cookbook)
|
||||||
* [Handling updates with a service](#handling-updates-with-a-service)
|
- [Handling updates with a service](#handling-updates-with-a-service)
|
||||||
- [DX (Developer Experience)](#dx-developer-experience)
|
- [DX (Developer Experience)](#dx-developer-experience)
|
||||||
* [`mypy` / type annotations](#mypy--type-annotations)
|
- [`mypy` / type annotations](#mypy--type-annotations)
|
||||||
- [Django Styleguide in the Wild](#django-styleguide-in-the-wild)
|
- [Django Styleguide in the Wild](#django-styleguide-in-the-wild)
|
||||||
- [Additional resources / Alternatives](#additional-resources--alternatives)
|
- [Additional resources / Alternatives](#additional-resources--alternatives)
|
||||||
- [Inspiration](#inspiration)
|
- [Inspiration](#inspiration)
|
||||||
|
@ -317,7 +317,7 @@ Now, if we try to create new object via `course.save()` or via `Course.objects.c
|
||||||
|
|
||||||
This can actually be a downside (_this is not the case, starting from Django 4.1. Check the extra section below._) to the approach, because now, we have to deal with the `IntegrityError`, which does not always have the best error message.
|
This can actually be a downside (_this is not the case, starting from Django 4.1. Check the extra section below._) to the approach, because now, we have to deal with the `IntegrityError`, which does not always have the best error message.
|
||||||
|
|
||||||
> 👀 ⚠️ 👀 Since Django 4.1, calling `.full_clean` will also check model constraints!
|
> 👀 ⚠️ 👀 Since Django 4.1, calling `.full_clean` will also check model constraints!
|
||||||
>
|
>
|
||||||
> This actually removes the downside, mentioned above, since you'll get a nice `ValidationError`, if your model constraints fail the check (if you go thru `Model.objects.create(...)` the downside still holds)
|
> This actually removes the downside, mentioned above, since you'll get a nice `ValidationError`, if your model constraints fail the check (if you go thru `Model.objects.create(...)` the downside still holds)
|
||||||
>
|
>
|
||||||
|
@ -449,7 +449,7 @@ Now, we can safely call `set_new_secret`, that'll produce correct values for bot
|
||||||
1. If the calculation of the derived value is simple enough.
|
1. If the calculation of the derived value is simple enough.
|
||||||
1. If setting one attribute always requires setting values to other attributes, use a method for that.
|
1. If setting one attribute always requires setting values to other attributes, use a method for that.
|
||||||
|
|
||||||
**Models should be something else (service, selector, utility) in the following cases:**
|
**Methods should be something else (service, selector, utility) in the following cases:**
|
||||||
|
|
||||||
1. If we need to span multiple relations or fetch additional data.
|
1. If we need to span multiple relations or fetch additional data.
|
||||||
1. If the calculation is more complex.
|
1. If the calculation is more complex.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user