Commit 41c15b6b authored by Myriam Begel's avatar Myriam Begel

Créer un formulaire de contact

parent a54da1fb
from django.contrib import admin
from .models import Publication
from .models import Publication, Contact
admin.site.register(Publication)
@admin.register(Contact)
class ContactAdmin(admin.ModelAdmin):
readonly_fields = ['nom', 'mail', 'raison', 'message', 'date']
from django.forms import ModelForm
from .models import Contact
class ContactForm(ModelForm):
class Meta:
model = Contact
fields = ['nom', 'mail', 'raison', 'message']
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2016-12-13 09:55
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('perso_app', '0002_auto_20161212_2336'),
]
operations = [
migrations.CreateModel(
name='Contact',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nom', models.CharField(max_length=50)),
('mail', models.EmailField(max_length=254)),
('raison', models.CharField(choices=[('perso', 'Contact personel'), ('pro', 'Contact professionel')], max_length=50)),
('message', models.TextField()),
('date', models.DateTimeField(auto_now_add=True)),
],
),
]
......@@ -9,3 +9,18 @@ class Publication(models.Model):
def __str__(self):
return self.titre
choices = (
('perso', 'Contact personel'),
('pro', 'Contact professionel')
)
class Contact(models.Model):
nom = models.CharField(max_length = 50)
mail = models.EmailField()
raison = models.CharField(choices = choices, max_length = 50)
message = models.TextField()
date = models.DateTimeField(auto_now_add = True)
def __str__(self):
return self.nom
......@@ -14,7 +14,7 @@
<ul>
<li> <a href="{% url 'accueil'%}"> Accueil </a> </li>
<li> <a href="{% url 'publications'%}"> Publications </a> </li>
<li> <a href="contact"> Contact </a> </li>
<li> <a href="{% url 'contact'%}"> Contact </a> </li>
</ul>
</nav>
</header>
......
{% extends 'perso_app/base.html' %}
{% block body %}
<form method="post" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Envoyer" />
</form>
{% endblock %}
......@@ -3,5 +3,6 @@ from . import views
urlpatterns = [
url(r'^$', views.accueil, name="accueil"),
url(r'^publications$', views.publications, name="publications")
url(r'^publications$', views.publications, name="publications"),
url(r'^contact$', views.contact, name="contact"),
]
from django.shortcuts import render
from .models import Publication
from django.http import HttpResponseRedirect
from django.urls import reverse
from .models import Publication, Contact
from .forms import ContactForm
def accueil(request):
return render(request, 'perso_app/index.html', {})
......@@ -8,3 +11,7 @@ def publications(request):
publications = Publication.objects.order_by('-date')
context = {'publications': publications}
return render(request, 'perso_app/publications.html', context)
def contact(request):
context = {'form': ContactForm()}
return render(request, 'perso_app/contact.html', context)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment