Adding form for creating new Person entries
This commit is contained in:
parent
49c26d96ad
commit
f49f6216ef
12
member/forms.py
Normal file
12
member/forms.py
Normal file
@ -0,0 +1,12 @@
|
||||
# forms.py
|
||||
|
||||
from django import forms
|
||||
from .models import Person
|
||||
|
||||
class PersonForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Person
|
||||
fields = ['vorname', 'nachname', 'geburtsdatum', 'aktiv']
|
||||
widgets = {
|
||||
'geburtsdatum': forms.DateInput(attrs={'type': 'date'}),
|
||||
}
|
||||
5
member/static/icons/heroicons/plus.svg
Normal file
5
member/static/icons/heroicons/plus.svg
Normal file
@ -0,0 +1,5 @@
|
||||
<!-- plus.svg -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M12 4v16m8-8H4" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 222 B |
@ -129,3 +129,31 @@ body {
|
||||
background-color: #d63031;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
vertical-align: middle;
|
||||
margin-right: 6px;
|
||||
filter: invert(90%); /* für helle SVGs in dunklem Hintergrund */
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: grid;
|
||||
flex-direction: column;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
margin-bottom: 4px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
padding: 8px;
|
||||
border: 1px solid #444;
|
||||
border-radius: 4px;
|
||||
background-color: #1e1e1e;
|
||||
color: #f1f1f1;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{% extends "master.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}
|
||||
List of all persons
|
||||
@ -7,13 +8,25 @@
|
||||
{% block content %}
|
||||
<div class="members-table">
|
||||
<h3>Members</h3>
|
||||
<ul>
|
||||
{% for x in mymembers %}
|
||||
<li><a href="details/{{x.id}}"> {{ x.vorname }} {{ x.nachname }}</a></li>
|
||||
{% empty %}
|
||||
<li>Keine Datensaetze gefunden</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{% url 'create' %}" class="button" title="Neues Mitglied"> <img src="{% static 'icons/heroicons/plus.svg' %}" alt="Neu" class="icon"> Neu</a>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Aktiv</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for x in mymembers %}
|
||||
<tr>
|
||||
<td><a href="{% url 'details' x.id %}">{{ x.nachname }} {{ x.vorname}}</a> </td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
27
member/templates/person_form.html
Normal file
27
member/templates/person_form.html
Normal file
@ -0,0 +1,27 @@
|
||||
{% extends "master.html" %}
|
||||
{% block content %}
|
||||
<div class="members-table">
|
||||
<h3>{{ action }} Person</h3>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label for="{{form.vorname.id_for_label}}">Vorname</label>
|
||||
{{form.vorname}}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="{{form.nachname.id_for_label}}">Nachname</label>
|
||||
{{ form.nachname}}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="{{form.geburtsdatum.id_for_label}}">Geburtsdatum</label>
|
||||
{{ form.geburtsdatum}}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="{{form.aktiv.id_for_label}}">Aktiv</label>
|
||||
{{ form.aktiv}}
|
||||
</div>
|
||||
<button class="button" type="submit">Speichern</button>
|
||||
<a href="{% url 'members' %}" class="button" style="background:#444;">Abbrechen</a>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -4,4 +4,5 @@ from . import views
|
||||
urlpatterns = [
|
||||
path('members/', views.members, name='members'),
|
||||
path('members/details/<int:id>', views.details, name="details"),
|
||||
path('members/create/', views.create, name="create"),
|
||||
]
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.template import loader
|
||||
from .models import Person
|
||||
from .forms import PersonForm
|
||||
|
||||
def members(request):
|
||||
mymembers=Person.objects.all().values()
|
||||
@ -17,3 +19,13 @@ def details(request, id):
|
||||
'mymember': mymember
|
||||
}
|
||||
return HttpResponse(template.render(context, request))
|
||||
|
||||
def create(request):
|
||||
if request.method == "POST":
|
||||
form = PersonForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect('members')
|
||||
else:
|
||||
form = PersonForm()
|
||||
return render(request, "person_form.html", {'form': form, 'action': "Neu anlegen"})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user