Enforce email address uniqueness

This commit is contained in:
Gabriel Augendre 2018-05-22 00:55:14 +02:00
parent c16d0db8ca
commit d88693b4b4
5 changed files with 18 additions and 10 deletions

View file

@ -1,4 +1,4 @@
# Generated by Django 2.0.5 on 2018-05-21 21:57 # Generated by Django 2.0.5 on 2018-05-21 22:47
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -50,8 +50,8 @@ class Migration(migrations.Migration):
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('first_name', models.CharField(max_length=100, verbose_name='prénom')), ('first_name', models.CharField(max_length=100, verbose_name='prénom')),
('last_name', models.CharField(max_length=100, verbose_name='nom')), ('last_name', models.CharField(max_length=100, verbose_name='nom')),
('phone_number', models.CharField(max_length=10, verbose_name='numéro de téléphone')), ('phone_number', models.CharField(help_text="En cas d'urgence", max_length=10, verbose_name='numéro de téléphone')),
('email', models.EmailField(max_length=254, verbose_name='adresse email')), ('email', models.EmailField(help_text='Utilisée pour vous transmettre votre lien personnel', max_length=254, unique=True, verbose_name='adresse email')),
], ],
options={ options={
'verbose_name': 'enseignant', 'verbose_name': 'enseignant',

View file

@ -12,8 +12,12 @@ class Teacher(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
first_name = models.CharField('prénom', max_length=100) first_name = models.CharField('prénom', max_length=100)
last_name = models.CharField('nom', max_length=100) last_name = models.CharField('nom', max_length=100)
phone_number = models.CharField('numéro de téléphone', max_length=10) phone_number = models.CharField('numéro de téléphone', help_text="En cas d'urgence", max_length=10)
email = models.EmailField('adresse email') email = models.EmailField(
'adresse email',
help_text='Utilisée pour vous transmettre votre lien personnel',
unique=True
)
def get_absolute_url(self): def get_absolute_url(self):
from django.urls import reverse from django.urls import reverse

View file

@ -6,12 +6,15 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<h1>Bienvenue {{ teacher.full_name }}</h1> <h1>Bienvenue {{ teacher.full_name }}</h1>
<h2>{% block title %}Ajouter un livre{% endblock %}</h2> <h2>
{% block title %}Ajouter un livre{% endblock %}
<a href="{% url 'list_books' teacher.pk %}" class="btn btn-secondary">Retour à la liste</a>
</h2>
<form action="" method="post" class="form"> <form action="" method="post" class="form">
{% csrf_token %} {% csrf_token %}
{% bootstrap_form form %} {% bootstrap_form form %}
{% buttons %} {% buttons %}
<button type="submit" class="btn btn-primary">Submit</button> <button type="submit" class="btn btn-primary">Valider</button>
{% endbuttons %} {% endbuttons %}
</form> </form>
</div> </div>

View file

@ -27,7 +27,7 @@
{% csrf_token %} {% csrf_token %}
{% bootstrap_form form %} {% bootstrap_form form %}
{% buttons %} {% buttons %}
<button type="submit" class="btn btn-primary">Submit</button> <button type="submit" class="btn btn-primary">Valider</button>
{% endbuttons %} {% endbuttons %}
</form> </form>
</div> </div>

View file

@ -20,8 +20,9 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<h2>{% block title %}Liste des livres demandés{% endblock %} <a href="{% url 'add_book' pk=teacher.pk %}" <h2>
class="btn btn-primary">Ajouter un livre</a> {% block title %}Liste des livres demandés{% endblock %}
<a href="{% url 'add_book' pk=teacher.pk %}" class="btn btn-primary">Ajouter un livre</a>
</h2> </h2>
<table class="table table-hover table-sm"> <table class="table table-hover table-sm">
<thead> <thead>