├── .gitignore ├── README.md ├── contrib └── env_gen.py ├── img ├── 1400605.jpg ├── admin_tabular_inline.png ├── auth_user_add.png ├── band_contact.png ├── dr_strange_failure.gif ├── login.png ├── mtv1.png ├── mtv3.png ├── password-change-form.png └── thor.gif ├── manage.py ├── myproject ├── __init__.py ├── accounts │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── templates │ │ └── accounts │ │ │ ├── login.html │ │ │ └── signup.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── asgi.py ├── core │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── management │ │ └── commands │ │ │ ├── __init__.py │ │ │ ├── create_data.py │ │ │ └── hello.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── static │ │ ├── css │ │ │ ├── form.css │ │ │ ├── icons │ │ │ │ └── simple-line-icons.min.css │ │ │ ├── login.css │ │ │ └── style.css │ │ ├── fonts │ │ │ ├── Simple-Line-Icons.eot │ │ │ ├── Simple-Line-Icons.svg │ │ │ ├── Simple-Line-Icons.ttf │ │ │ ├── Simple-Line-Icons.woff │ │ │ └── Simple-Line-Icons.woff2 │ │ ├── img │ │ │ └── django-logo-negative.png │ │ └── js │ │ │ └── django-ajax-setup.js │ ├── templates │ │ ├── base.html │ │ ├── base_login.html │ │ ├── includes │ │ │ ├── nav.html │ │ │ └── pagination.html │ │ └── index.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── crm │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── forms.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── 0002_auto_20210606_1948.py │ │ └── __init__.py │ ├── models.py │ ├── templates │ │ └── crm │ │ │ ├── contact_form.html │ │ │ ├── person_bootstrap_form.html │ │ │ ├── person_confirm_delete.html │ │ │ ├── person_crispy_form.html │ │ │ ├── person_detail.html │ │ │ ├── person_form.html │ │ │ ├── person_form0.html │ │ │ ├── person_form1.html │ │ │ ├── person_form2.html │ │ │ ├── person_list.html │ │ │ ├── person_modal.html │ │ │ ├── person_photo_form.html │ │ │ └── person_vuejs_list.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── settings.py ├── urls.py ├── utils │ ├── progress_bar.py │ └── utils.py └── wsgi.py ├── passo-a-passo.md └── requirements.txt /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # django-forms-tutorial 2 | 3 | Tutorial sobre formulários do Django para Live no YouTube. 4 | 5 | 6 | ## Este projeto foi feito com: 7 | 8 | * [Python 3.9.4](https://www.python.org/) 9 | * [Django 3.2.4](https://www.djangoproject.com/) 10 | 11 | 12 | ## Como rodar o projeto? 13 | 14 | * Clone esse repositório. 15 | * Crie um virtualenv com Python 3. 16 | * Ative o virtualenv. 17 | * Instale as dependências. 18 | * Rode as migrações. 19 | 20 | ``` 21 | git clone https://github.com/rg3915/django-forms-tutorial.git 22 | cd django-forms-tutorial 23 | python -m venv .venv 24 | source .venv/bin/activate 25 | pip install -r requirements.txt 26 | python contrib/env_gen.py 27 | python manage.py migrate 28 | python manage.py createsuperuser --username="admin" --email="" 29 | ``` 30 | 31 | Leia o [passo-a-passo.md](passo-a-passo.md) 32 | 33 |  34 | 35 | --- 36 | 37 |  38 | 39 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /img/1400605.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/img/1400605.jpg -------------------------------------------------------------------------------- /img/admin_tabular_inline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/img/admin_tabular_inline.png -------------------------------------------------------------------------------- /img/auth_user_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/img/auth_user_add.png -------------------------------------------------------------------------------- /img/band_contact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/img/band_contact.png -------------------------------------------------------------------------------- /img/dr_strange_failure.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/img/dr_strange_failure.gif -------------------------------------------------------------------------------- /img/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/img/login.png -------------------------------------------------------------------------------- /img/mtv1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/img/mtv1.png -------------------------------------------------------------------------------- /img/mtv3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/img/mtv3.png -------------------------------------------------------------------------------- /img/password-change-form.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/img/password-change-form.png -------------------------------------------------------------------------------- /img/thor.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/img/thor.gif -------------------------------------------------------------------------------- /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/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/myproject/__init__.py -------------------------------------------------------------------------------- /myproject/accounts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/myproject/accounts/__init__.py -------------------------------------------------------------------------------- /myproject/accounts/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /myproject/accounts/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class AccountsConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'myproject.accounts' 7 | -------------------------------------------------------------------------------- /myproject/accounts/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/myproject/accounts/migrations/__init__.py -------------------------------------------------------------------------------- /myproject/accounts/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /myproject/accounts/templates/accounts/login.html: -------------------------------------------------------------------------------- 1 | {% extends "base_login.html" %} 2 | {% load static %} 3 | 4 | {% block title %}Login{% endblock title %} 5 | 6 | {% block content %} 7 |
{{ error }}
17 | {% endfor %} 18 | {% endif %} 19 | 20 | 47 | 48 |Crie sua conta.
14 | 15 | 51 |Página simples.
') 8 | 9 | 10 | # @login_required 11 | def index(request): 12 | template_name = 'index.html' 13 | return render(request, template_name) 14 | -------------------------------------------------------------------------------- /myproject/crm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/myproject/crm/__init__.py -------------------------------------------------------------------------------- /myproject/crm/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import Person, Photo 4 | 5 | 6 | @admin.register(Person) 7 | class PersonAdmin(admin.ModelAdmin): 8 | list_display = ('__str__', 'email', 'active') 9 | # readonly_fields = ('slug',) 10 | # list_display_links = ('name',) 11 | search_fields = ('first_name', 'last_name', 'email') 12 | list_filter = ('active',) 13 | # date_hierarchy = 'created' 14 | # ordering = ('-created',) 15 | # actions = ('',) 16 | 17 | 18 | admin.site.register(Photo) 19 | -------------------------------------------------------------------------------- /myproject/crm/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CrmConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'myproject.crm' 7 | -------------------------------------------------------------------------------- /myproject/crm/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | 3 | from .models import Person 4 | 5 | 6 | class PersonForm0(forms.ModelForm): 7 | required_css_class = 'required' 8 | 9 | class Meta: 10 | model = Person 11 | fields = ('first_name', 'last_name') 12 | 13 | 14 | class PersonForm1(forms.ModelForm): 15 | required_css_class = 'required' 16 | 17 | class Meta: 18 | model = Person 19 | fields = ('first_name', 'last_name') 20 | 21 | def __init__(self, *args, **kwargs): 22 | super(PersonForm1, self).__init__(*args, **kwargs) 23 | for field_name, field in self.fields.items(): 24 | field.widget.attrs['class'] = 'form-control' 25 | 26 | 27 | class PersonForm2(forms.ModelForm): 28 | required_css_class = 'required' 29 | 30 | class Meta: 31 | model = Person 32 | fields = ('first_name', 'last_name', 'email') 33 | 34 | def __init__(self, *args, **kwargs): 35 | super(PersonForm2, self).__init__(*args, **kwargs) 36 | for field_name, field in self.fields.items(): 37 | field.widget.attrs['class'] = 'form-control' 38 | 39 | 40 | class PersonForm(forms.ModelForm): 41 | required_css_class = 'required' 42 | 43 | class Meta: 44 | model = Person 45 | # fields = '__all__' 46 | fields = ( 47 | 'first_name', 48 | 'last_name', 49 | 'email', 50 | 'address', 51 | 'address_number', 52 | 'complement', 53 | 'district', 54 | 'city', 55 | 'uf', 56 | 'cep', 57 | 'country', 58 | 'cpf', 59 | 'rg', 60 | 'cnh', 61 | 'active', 62 | ) 63 | 64 | def __init__(self, *args, **kwargs): 65 | super(PersonForm, self).__init__(*args, **kwargs) 66 | for field_name, field in self.fields.items(): 67 | field.widget.attrs['class'] = 'form-control' 68 | self.fields['active'].widget.attrs['class'] = None 69 | 70 | 71 | class ContactForm(forms.Form): 72 | subject = forms.CharField(max_length=100) 73 | message = forms.CharField(widget=forms.Textarea) 74 | sender = forms.EmailField() 75 | cc_myself = forms.BooleanField(required=False) 76 | 77 | 78 | class PersonPhotoForm(forms.ModelForm): 79 | required_css_class = 'required' 80 | # photo = forms.ImageField(required=False) 81 | photo = forms.ImageField( 82 | required=False, 83 | widget=forms.ClearableFileInput(attrs={'multiple': True}) 84 | ) 85 | 86 | class Meta: 87 | model = Person 88 | fields = ('first_name', 'last_name', 'photo') 89 | 90 | def __init__(self, *args, **kwargs): 91 | super(PersonPhotoForm, self).__init__(*args, **kwargs) 92 | for field_name, field in self.fields.items(): 93 | field.widget.attrs['class'] = 'form-control' 94 | self.fields['photo'].widget.attrs['class'] = None 95 | -------------------------------------------------------------------------------- /myproject/crm/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.2.4 on 2021-06-06 18:39 2 | 3 | import uuid 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | ] 14 | 15 | operations = [ 16 | migrations.CreateModel( 17 | name='Person', 18 | fields=[ 19 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 20 | ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)), 21 | ('created', models.DateTimeField(auto_now_add=True, verbose_name='criado em')), 22 | ('modified', models.DateTimeField(auto_now=True, verbose_name='modificado em')), 23 | ('address', models.CharField(blank=True, max_length=100, null=True, verbose_name='endereço')), 24 | ('address_number', models.IntegerField(blank=True, null=True, verbose_name='número')), 25 | ('complement', models.CharField(blank=True, max_length=100, null=True, verbose_name='complemento')), 26 | ('district', models.CharField(blank=True, max_length=100, null=True, verbose_name='bairro')), 27 | ('city', models.CharField(blank=True, max_length=100, null=True, verbose_name='cidade')), 28 | ('uf', models.CharField(blank=True, choices=[('AC', 'Acre'), ('AL', 'Alagoas'), ('AP', 'Amapá'), ('AM', 'Amazonas'), ('BA', 'Bahia'), ('CE', 'Ceará'), ('DF', 'Distrito Federal'), ('ES', 'Espírito Santo'), ('GO', 'Goiás'), ('MA', 'Maranhão'), ('MT', 'Mato Grosso'), ('MS', 'Mato Grosso do Sul'), ('MG', 'Minas Gerais'), ('PA', 'Pará'), ('PB', 'Paraíba'), ('PR', 'Paraná'), ('PE', 'Pernambuco'), ('PI', 'Piauí'), ('RJ', 'Rio de Janeiro'), ('RN', 'Rio Grande do Norte'), ('RS', 'Rio Grande do Sul'), ('RO', 'Rondônia'), ('RR', 'Roraima'), ('SC', 'Santa Catarina'), ('SP', 'São Paulo'), ('SE', 'Sergipe'), ('TO', 'Tocantins')], max_length=2, null=True, verbose_name='UF')), 29 | ('cep', models.CharField(blank=True, max_length=9, null=True, verbose_name='CEP')), 30 | ('country', models.CharField(blank=True, default='Brasil', max_length=50, null=True, verbose_name='país')), 31 | ('cpf', models.CharField(blank=True, max_length=11, null=True, unique=True, verbose_name='CPF')), 32 | ('rg', models.CharField(blank=True, max_length=11, null=True, verbose_name='RG')), 33 | ('cnh', models.CharField(blank=True, max_length=20, null=True, verbose_name='CNH')), 34 | ('active', models.BooleanField(default=True, verbose_name='ativo')), 35 | ('exist_deleted', models.BooleanField(default=True, help_text='Se for True o item existe. Se for False o item foi deletado.', verbose_name='existe/deletado')), 36 | ('first_name', models.CharField(max_length=50, verbose_name='nome')), 37 | ('last_name', models.CharField(blank=True, max_length=50, null=True, verbose_name='sobrenome')), 38 | ('email', models.EmailField(blank=True, max_length=254, null=True)), 39 | ], 40 | options={ 41 | 'verbose_name': 'pessoa', 42 | 'verbose_name_plural': 'pessoas', 43 | 'ordering': ('first_name',), 44 | }, 45 | ), 46 | ] 47 | -------------------------------------------------------------------------------- /myproject/crm/migrations/0002_auto_20210606_1948.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.2.4 on 2021-06-06 22:48 2 | 3 | import django.db.models.deletion 4 | from django.db import migrations, models 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('crm', '0001_initial'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AlterField( 15 | model_name='person', 16 | name='first_name', 17 | field=models.CharField(help_text='Digite somente o primeiro nome.', max_length=50, verbose_name='nome'), 18 | ), 19 | migrations.CreateModel( 20 | name='Photo', 21 | fields=[ 22 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 23 | ('photo', models.ImageField(upload_to='', verbose_name='foto')), 24 | ('person', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='photos', to='crm.person', verbose_name='foto')), 25 | ], 26 | options={ 27 | 'verbose_name': 'foto', 28 | 'verbose_name_plural': 'fotos', 29 | 'ordering': ('pk',), 30 | }, 31 | ), 32 | ] 33 | -------------------------------------------------------------------------------- /myproject/crm/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-forms-tutorial/0288a8c28760e7f1465ba2a2f675245fafed9bf1/myproject/crm/migrations/__init__.py -------------------------------------------------------------------------------- /myproject/crm/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.urls import reverse_lazy 3 | 4 | from myproject.core.models import ( 5 | Active, 6 | Address, 7 | Document, 8 | TimeStampedModel, 9 | UuidModel 10 | ) 11 | 12 | 13 | class Person(UuidModel, TimeStampedModel, Address, Document, Active): 14 | first_name = models.CharField('nome', max_length=50, help_text='Digite somente o primeiro nome.') 15 | last_name = models.CharField('sobrenome', max_length=50, null=True, blank=True) # noqa E501 16 | email = models.EmailField(null=True, blank=True) 17 | 18 | class Meta: 19 | ordering = ('first_name',) 20 | verbose_name = 'pessoa' 21 | verbose_name_plural = 'pessoas' 22 | 23 | @property 24 | def full_name(self): 25 | return f'{self.first_name} {self.last_name or ""}'.strip() 26 | 27 | def __str__(self): 28 | return self.full_name 29 | 30 | def get_absolute_url(self): 31 | return reverse_lazy('crm:person_detail', kwargs={'pk': self.pk}) 32 | 33 | def to_dict(self): 34 | return { 35 | 'id': self.id, 36 | 'first_name': self.first_name, 37 | 'last_name': self.last_name, 38 | 'email': self.email, 39 | } 40 | 41 | 42 | class Photo(models.Model): 43 | photo = models.ImageField('foto', upload_to='') 44 | person = models.ForeignKey( 45 | Person, 46 | on_delete=models.CASCADE, 47 | verbose_name='foto', 48 | related_name='photos', 49 | ) 50 | 51 | class Meta: 52 | ordering = ('pk',) 53 | verbose_name = 'foto' 54 | verbose_name_plural = 'fotos' 55 | 56 | def __str__(self): 57 | return str(self.person) 58 | -------------------------------------------------------------------------------- /myproject/crm/templates/crm/contact_form.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% load widget_tweaks %} 3 | 4 | {% block title %} 5 |Nome | 15 |Ações | 17 ||
---|---|---|
23 | {{ object.full_name }} 24 | | 25 |{{ object.email|default:'---' }} | 26 |27 | 28 | 29 | 30 | 31 | 32 | 33 | | 34 |
Nome | 55 |Ações | 57 ||
---|---|---|
62 | ${ person | fullName } 63 | | 64 |${ person.email } | 65 |66 | 67 | 68 | | 69 |
Nome | 1232 ||
---|---|
1238 | ${ person | fullName } 1239 | | 1240 |${ person.email } | 1241 |