├── myproject
├── __init__.py
├── core
│ ├── __init__.py
│ ├── management
│ │ ├── __init__.py
│ │ └── commands
│ │ │ ├── __init__.py
│ │ │ └── create_data.py
│ ├── migrations
│ │ ├── __init__.py
│ │ └── 0001_initial.py
│ ├── tests.py
│ ├── apps.py
│ ├── admin.py
│ ├── static
│ │ └── js
│ │ │ └── data.js
│ ├── urls.py
│ ├── models.py
│ ├── templates
│ │ ├── nav.html
│ │ ├── persons_serverside.html
│ │ ├── base.html
│ │ └── index.html
│ └── views.py
├── urls.py
├── asgi.py
├── wsgi.py
└── settings.py
├── requirements.txt
├── DataTables-ServerSide-diagram.png
├── manage.py
├── contrib
└── env_gen.py
├── README.md
└── .gitignore
/myproject/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/myproject/core/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/myproject/core/management/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/myproject/core/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/myproject/core/management/commands/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/myproject/core/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | dj-database-url==0.5.*
2 | Django==3.2.*
3 | django-extensions==3.1.*
4 | Faker==8.12.*
5 | python-decouple==3.4
6 |
--------------------------------------------------------------------------------
/DataTables-ServerSide-diagram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rg3915/django-datatables-experiment/main/DataTables-ServerSide-diagram.png
--------------------------------------------------------------------------------
/myproject/core/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class CoreConfig(AppConfig):
5 | default_auto_field = 'django.db.models.BigAutoField'
6 | name = 'myproject.core'
7 |
--------------------------------------------------------------------------------
/myproject/urls.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 | from django.urls import include, path
3 |
4 | urlpatterns = [
5 | path('', include('myproject.core.urls')),
6 | path('admin/', admin.site.urls),
7 | ]
8 |
--------------------------------------------------------------------------------
/myproject/core/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | from .models import Person
4 |
5 |
6 | @admin.register(Person)
7 | class PersonAdmin(admin.ModelAdmin):
8 | list_display = ('__str__', 'email', 'phone')
9 | search_fields = ('name', 'email')
10 | list_filter = ('status',)
11 |
--------------------------------------------------------------------------------
/myproject/core/static/js/data.js:
--------------------------------------------------------------------------------
1 | $(document).ready( function () {
2 | $('#myTable1').DataTable();
3 |
4 | $('#myTable2').DataTable({
5 | "ajax": "/person/json/",
6 | "columns": [
7 | {"data": "name"},
8 | {"data": "email"},
9 | {"data": "phone"},
10 | {"data": "status"}
11 | ]
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/myproject/core/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 |
3 | from myproject.core import views as v
4 |
5 | app_name = 'core'
6 |
7 | urlpatterns = [
8 | path('', v.index, name='index'),
9 | path('persons/serverside/', v.persons_serverside, name='persons_serverside'), # noqa E501
10 | path('person/json/', v.person_json, name='person_json'),
11 | ]
12 |
--------------------------------------------------------------------------------
/myproject/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for myproject project.
3 |
4 | It exposes the ASGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.asgi import get_asgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/myproject/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for myproject project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | """Run administrative tasks."""
9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
10 | try:
11 | from django.core.management import execute_from_command_line
12 | except ImportError as exc:
13 | raise ImportError(
14 | "Couldn't import Django. Are you sure it's installed and "
15 | "available on your PYTHONPATH environment variable? Did you "
16 | "forget to activate a virtual environment?"
17 | ) from exc
18 | execute_from_command_line(sys.argv)
19 |
20 |
21 | if __name__ == '__main__':
22 | main()
23 |
--------------------------------------------------------------------------------
/myproject/core/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | STATUS = (
4 | ('0', ''),
5 | ('p', 'pendente'),
6 | ('c', 'cancelado'),
7 | ('a', 'aprovado'),
8 | )
9 |
10 |
11 | class Person(models.Model):
12 | name = models.CharField('nome', max_length=100)
13 | email = models.EmailField(null=True, blank=True)
14 | phone = models.CharField('telefone', max_length=11, null=True, blank=True)
15 | status = models.CharField(
16 | max_length=1,
17 | choices=STATUS,
18 | default='p'
19 | )
20 |
21 | class Meta:
22 | ordering = ('name',)
23 | verbose_name = 'Pessoa'
24 | verbose_name_plural = 'Pessoas'
25 |
26 | def __str__(self):
27 | return self.name
28 |
29 | def to_dict_json(self):
30 | return {
31 | 'pk': self.pk,
32 | 'name': self.name,
33 | 'email': self.email,
34 | 'phone': self.phone,
35 | 'status': self.get_status_display(),
36 | }
37 |
--------------------------------------------------------------------------------
/contrib/env_gen.py:
--------------------------------------------------------------------------------
1 | """
2 | Python SECRET_KEY generator.
3 | """
4 | import random
5 |
6 | chars = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!?@#$%^&*()"
7 | size = 50
8 | secret_key = "".join(random.sample(chars, size))
9 |
10 | chars = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!?@#$%_"
11 | size = 20
12 | password = "".join(random.sample(chars, size))
13 |
14 | CONFIG_STRING = """
15 | DEBUG=True
16 | SECRET_KEY=%s
17 | ALLOWED_HOSTS=127.0.0.1,.localhost,0.0.0.0
18 |
19 | #DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/NAME
20 | #POSTGRES_DB=
21 | #POSTGRES_USER=
22 | #POSTGRES_PASSWORD=%s
23 | #DB_HOST=localhost
24 |
25 | #DEFAULT_FROM_EMAIL=
26 | #EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
27 | #EMAIL_HOST=localhost
28 | #EMAIL_PORT=
29 | #EMAIL_HOST_USER=
30 | #EMAIL_HOST_PASSWORD=
31 | #EMAIL_USE_TLS=True
32 | """.strip() % (secret_key, password)
33 |
34 | # Writing our configuration file to '.env'
35 | with open('.env', 'w') as configfile:
36 | configfile.write(CONFIG_STRING)
37 |
38 | print('Success!')
39 | print('Type: cat .env')
40 |
--------------------------------------------------------------------------------
/myproject/core/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.2.7 on 2021-09-12 21:55
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | initial = True
9 |
10 | dependencies = [
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='Person',
16 | fields=[
17 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18 | ('name', models.CharField(max_length=100, verbose_name='nome')),
19 | ('email', models.EmailField(blank=True, max_length=254, null=True)),
20 | ('phone', models.CharField(blank=True, max_length=11, null=True, verbose_name='telefone')),
21 | ('status', models.CharField(choices=[('0', ''), ('p', 'pendente'), ('c', 'cancelado'), ('a', 'aprovado')], default='p', max_length=1)),
22 | ],
23 | options={
24 | 'verbose_name': 'Pessoa',
25 | 'verbose_name_plural': 'Pessoas',
26 | 'ordering': ('name',),
27 | },
28 | ),
29 | ]
30 |
--------------------------------------------------------------------------------
/myproject/core/templates/nav.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/myproject/core/templates/persons_serverside.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 | {% load static %}
3 |
4 | {% block content %}
5 |
6 |
12 |
13 |
14 |
15 |
16 |
DataTables Server-side render
17 |
18 |
19 |
20 | | Nome |
21 | E-mail |
22 | Telefone |
23 | Gênero |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | {% endblock content %}
35 |
36 | {% block js %}
37 |
38 |
54 |
55 | {% endblock js %}
56 |
--------------------------------------------------------------------------------
/myproject/core/views.py:
--------------------------------------------------------------------------------
1 | import math
2 |
3 | from django.db.models import Q
4 | from django.http import JsonResponse
5 | from django.shortcuts import render
6 |
7 | from .models import Person
8 |
9 |
10 | def index(request):
11 | person_list = Person.objects.all()
12 | context = {'person_list': person_list}
13 | return render(request, 'index.html', context)
14 |
15 |
16 | def person_json(request):
17 | persons = Person.objects.all()
18 | total = persons.count()
19 |
20 | search = request.GET.get('search[value]')
21 |
22 | if search:
23 | persons = persons.filter(
24 | Q(name__icontains=search) |
25 | Q(email__icontains=search) |
26 | Q(phone__icontains=search)
27 | )
28 |
29 | _start = request.GET.get('start')
30 | _length = request.GET.get('length')
31 | if _start and _length:
32 | start = int(_start)
33 | length = int(_length)
34 | page = math.ceil(start / length) + 1 # [opcional]
35 | per_page = length # [opcional]
36 |
37 | persons = persons[start:start + length]
38 |
39 | data = [person.to_dict_json() for person in persons]
40 | response = {
41 | 'data': data,
42 | 'recordsTotal': total,
43 | 'recordsFiltered': total,
44 | }
45 | return JsonResponse(response)
46 |
47 |
48 | def persons_serverside(request):
49 | template_name = 'persons_serverside.html'
50 | return render(request, template_name)
51 |
--------------------------------------------------------------------------------
/myproject/core/templates/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | DataTables example
20 |
21 |
26 |
27 |
28 |
29 | {% include "nav.html" %}
30 |
31 |
32 |
33 | {% block content %}{% endblock content %}
34 |
35 |
36 |
37 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | {% block js %}{% endblock js %}
47 |
48 |
--------------------------------------------------------------------------------
/myproject/core/management/commands/create_data.py:
--------------------------------------------------------------------------------
1 | import string
2 | from random import choice
3 |
4 | from django.core.management.base import BaseCommand
5 | from django.utils.text import slugify
6 | from faker import Faker
7 |
8 | from myproject.core.models import Person
9 |
10 | fake = Faker()
11 |
12 |
13 | def gen_digits(max_length: int):
14 | '''Gera dígitos numéricos.'''
15 | return str(''.join(choice(string.digits) for i in range(max_length)))
16 |
17 |
18 | def gen_first_name():
19 | return fake.first_name()
20 |
21 |
22 | def gen_last_name():
23 | return fake.last_name()
24 |
25 |
26 | def gen_email(first_name: str, last_name: str, company: str = None):
27 | first_name = slugify(first_name)
28 | last_name = slugify(last_name)
29 | email = f'{first_name}.{last_name}@email.com'
30 | return email
31 |
32 |
33 | def gen_phone():
34 | return f'{gen_digits(2)} {gen_digits(4)}-{gen_digits(4)}'
35 |
36 |
37 | def gen_status():
38 | return choice(('p', 'c', 'a'))
39 |
40 |
41 | def create_person():
42 | aux_list = []
43 | Person.objects.all().delete()
44 | for _ in range(100):
45 | name = f'{fake.first_name()} {fake.last_name()}'
46 | email = f'{slugify(name)}@email.com'
47 | phone = gen_phone()
48 | status = gen_status()
49 | obj = Person(
50 | name=name,
51 | email=email,
52 | phone=phone,
53 | status=status,
54 | )
55 | aux_list.append(obj)
56 |
57 | Person.objects.bulk_create(aux_list)
58 |
59 |
60 | class Command(BaseCommand):
61 | help = "Create person data."
62 |
63 | def handle(self, *args, **options):
64 | create_person()
65 |
--------------------------------------------------------------------------------
/myproject/core/templates/index.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 | {% load static %}
3 |
4 | {% block content %}
5 |
6 |
7 |
8 |
9 |
10 |
Exemplo do uso de DataTables com Django.
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
Contatos
20 |
21 |
22 |
23 | | Nome |
24 | E-mail |
25 | Telefone |
26 | Status |
27 |
28 |
29 |
30 | {% for person in person_list %}
31 |
32 | | {{ person.name }} |
33 | {{ person.email }} |
34 | {{ person.phone }} |
35 | {{ person.get_status_display }} |
36 |
37 | {% endfor %}
38 |
39 |
40 |
41 |
42 |
Contatos via JSON
43 |
44 |
45 |
46 | | Nome |
47 | E-mail |
48 | Telefone |
49 | Status |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | {% endblock content %}
61 |
62 | {% block js %}
63 |
64 |
65 |
66 | {% endblock js %}
67 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # django-datatables-experiment
2 |
3 | Experiment with Django and DataTables.
4 |
5 | [Video no YouTube](https://www.youtube.com/watch?v=NeZ39HE_zKg)
6 |
7 |
8 | ## Como rodar este projeto?
9 |
10 | * Clone esse repositório.
11 | * Crie um virtualenv com Python 3.
12 | * Ative o virtualenv.
13 | * Instale as dependências.
14 | * Rode as migrações.
15 |
16 | ```
17 | git clone https://github.com/rg3915/django-datatables-experiment.git
18 | cd django-datatables-experiment
19 | python -m venv .venv
20 | source .venv/bin/activate
21 | pip install -r requirements.txt
22 | python contrib/env_gen.py
23 | python manage.py migrate
24 | ```
25 |
26 | ## Reescrevendo o projeto a partir da base
27 |
28 | ```
29 | git clone https://github.com/rg3915/django-datatables-experiment.git --branch base
30 | cd django-datatables-experiment
31 | python -m venv .venv
32 | source .venv/bin/activate
33 | pip install -r requirements.txt
34 | python contrib/env_gen.py
35 | ```
36 |
37 |
38 | ```python
39 | # models.py
40 | class Person(models.Model):
41 | ...
42 | status = models.CharField(
43 | max_length=1,
44 | choices=STATUS,
45 | default='p'
46 | )
47 | ```
48 |
49 |
50 | ```python
51 | # create_data.py
52 | def create_person():
53 | aux_list = []
54 | Person.objects.all().delete()
55 | for _ in range(100):
56 | name = f'{fake.first_name()} {fake.last_name()}'
57 | email = f'{slugify(name)}@email.com'
58 | phone = gen_phone()
59 | status = gen_status() # <---
60 | obj = Person(
61 | name=name,
62 | email=email,
63 | phone=phone,
64 | status=status, # <---
65 | )
66 | aux_list.append(obj)
67 | ```
68 |
69 | Após remodelar `models.py` faça
70 |
71 |
72 | ```
73 | python manage.py makemigrations
74 | python manage.py migrate
75 | python manage.py create_data
76 | ```
77 |
78 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 |
131 | .DS_Store
132 |
133 | media/
134 | staticfiles/
135 | .idea
136 | .ipynb_checkpoints/
137 | .vscode
138 |
--------------------------------------------------------------------------------
/myproject/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for myproject project.
3 |
4 | Generated by 'django-admin startproject' using Django 3.2.7.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.2/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/3.2/ref/settings/
11 | """
12 |
13 | from pathlib import Path
14 |
15 | from decouple import Csv, config
16 | from dj_database_url import parse as dburl
17 |
18 | # Build paths inside the project like this: BASE_DIR / 'subdir'.
19 | BASE_DIR = Path(__file__).resolve().parent.parent
20 |
21 |
22 | # Quick-start development settings - unsuitable for production
23 | # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
24 |
25 | # SECURITY WARNING: keep the secret key used in production secret!
26 | SECRET_KEY = config('SECRET_KEY')
27 |
28 | # SECURITY WARNING: don't run with debug turned on in production!
29 | DEBUG = config('DEBUG', default=False, cast=bool)
30 |
31 | ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=[], cast=Csv())
32 |
33 | # Application definition
34 |
35 | INSTALLED_APPS = [
36 | 'django.contrib.admin',
37 | 'django.contrib.auth',
38 | 'django.contrib.contenttypes',
39 | 'django.contrib.sessions',
40 | 'django.contrib.messages',
41 | 'django.contrib.staticfiles',
42 | # 3rd apps
43 | 'django_extensions',
44 | # my apps
45 | # 'myproject.core.apps.CoreConfig',
46 | 'myproject.core',
47 | ]
48 |
49 | MIDDLEWARE = [
50 | 'django.middleware.security.SecurityMiddleware',
51 | 'django.contrib.sessions.middleware.SessionMiddleware',
52 | 'django.middleware.common.CommonMiddleware',
53 | 'django.middleware.csrf.CsrfViewMiddleware',
54 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
55 | 'django.contrib.messages.middleware.MessageMiddleware',
56 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
57 | ]
58 |
59 | ROOT_URLCONF = 'myproject.urls'
60 |
61 | TEMPLATES = [
62 | {
63 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
64 | 'DIRS': [],
65 | 'APP_DIRS': True,
66 | 'OPTIONS': {
67 | 'context_processors': [
68 | 'django.template.context_processors.debug',
69 | 'django.template.context_processors.request',
70 | 'django.contrib.auth.context_processors.auth',
71 | 'django.contrib.messages.context_processors.messages',
72 | ],
73 | },
74 | },
75 | ]
76 |
77 | WSGI_APPLICATION = 'myproject.wsgi.application'
78 |
79 |
80 | # Database
81 | # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
82 |
83 | default_dburl = 'sqlite:///' + str(BASE_DIR / 'db.sqlite3')
84 | DATABASES = {
85 | 'default': config('DATABASE_URL', default=default_dburl, cast=dburl),
86 | }
87 |
88 |
89 | # Password validation
90 | # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
91 |
92 | AUTH_PASSWORD_VALIDATORS = [
93 | {
94 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
95 | },
96 | {
97 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
98 | },
99 | {
100 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
101 | },
102 | {
103 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
104 | },
105 | ]
106 |
107 |
108 | # Internationalization
109 | # https://docs.djangoproject.com/en/3.2/topics/i18n/
110 |
111 | LANGUAGE_CODE = 'pt-br' # 'en-us'
112 |
113 | TIME_ZONE = 'America/Sao_Paulo' # 'UTC'
114 |
115 | USE_I18N = True
116 |
117 | USE_L10N = True
118 |
119 | USE_TZ = True
120 |
121 | USE_THOUSAND_SEPARATOR = True
122 |
123 |
124 | # Static files (CSS, JavaScript, Images)
125 | # https://docs.djangoproject.com/en/3.2/howto/static-files/
126 |
127 | STATIC_URL = '/static/'
128 | STATIC_ROOT = BASE_DIR.joinpath('staticfiles')
129 |
130 | # Default primary key field type
131 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
132 |
133 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
134 |
--------------------------------------------------------------------------------