1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
-from django.contrib import admin
+from django.contrib import admin, auth
from django.urls import include, path
urlpatterns = [
path('mannschaft/', include('mannschaft.urls')),
path('admin/', admin.site.urls),
+ path('accounts/', include('django.contrib.auth.urls')),
]
-# Generated by Django 2.1.3 on 2018-11-03 01:05
+# Generated by Django 2.1.4 on 2018-12-04 21:30
+from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
initial = True
dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('begin', models.DateTimeField()),
('end', models.DateTimeField()),
- ('optional', models.TextField()),
+ ('optional', models.TextField(blank=True, null=True)),
],
),
migrations.CreateModel(
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
- ('street', models.CharField(max_length=100)),
- ('zip', models.IntegerField()),
- ('city', models.CharField(max_length=100)),
- ('additional', models.CharField(max_length=100)),
+ ('street', models.CharField(blank=True, max_length=100, null=True)),
+ ('zip', models.IntegerField(blank=True, null=True)),
+ ('city', models.CharField(blank=True, max_length=100, null=True)),
+ ('additional', models.CharField(blank=True, max_length=100, null=True)),
],
),
migrations.CreateModel(
name='Player',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('name', models.CharField(max_length=50)),
- ('firstname', models.CharField(max_length=50)),
- ('birthdate', models.DateField()),
- ('dsvid', models.IntegerField()),
+ ('birthdate', models.DateField(blank=True, null=True)),
+ ('dsvid', models.IntegerField(blank=True, null=True)),
],
),
migrations.CreateModel(
name='PlayerState',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('state', models.CharField(max_length=1)),
- ('reason', models.CharField(max_length=180)),
+ ('state', models.CharField(choices=[('y', 'Ja'), ('n', 'Nein'), ('p', 'Vielleicht')], max_length=1)),
+ ('reason', models.CharField(blank=True, max_length=180, null=True)),
],
),
migrations.CreateModel(
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
- ('min_age', models.IntegerField(default=0)),
- ('max_age', models.IntegerField(default=999)),
- ('players', models.ManyToManyField(to='mannschaft.Player')),
+ ('min_age', models.IntegerField(blank=True, default=0, null=True)),
+ ('max_age', models.IntegerField(blank=True, default=999, null=True)),
+ ('players', models.ManyToManyField(blank=True, to='mannschaft.Player')),
+ ('trainers', models.ManyToManyField(blank=True, related_name='trainers', to='mannschaft.Player')),
],
),
migrations.CreateModel(
('event_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='mannschaft.Event')),
('home', models.BooleanField()),
('opponent', models.CharField(max_length=50)),
- ('score_team', models.IntegerField()),
- ('score_opponent', models.IntegerField()),
+ ('score_team', models.IntegerField(blank=True, null=True)),
+ ('score_opponent', models.IntegerField(blank=True, null=True)),
],
bases=('mannschaft.event',),
),
),
migrations.AddField(
model_name='playerstate',
- name='game',
+ name='event',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Event'),
),
migrations.AddField(
name='player',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Player'),
),
+ migrations.AddField(
+ model_name='player',
+ name='teams',
+ field=models.ManyToManyField(blank=True, to='mannschaft.Team'),
+ ),
+ migrations.AddField(
+ model_name='player',
+ name='user',
+ field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
+ ),
migrations.AddField(
model_name='event',
name='location',
- field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Location'),
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Location'),
+ ),
+ migrations.AddField(
+ model_name='event',
+ name='state',
+ field=models.ManyToManyField(blank=True, related_name='event_player_state', through='mannschaft.PlayerState', to='mannschaft.Player'),
),
migrations.AddField(
model_name='event',
name='tasks',
- field=models.ManyToManyField(through='mannschaft.Task', to='mannschaft.Player'),
+ field=models.ManyToManyField(blank=True, through='mannschaft.Task', to='mannschaft.Player'),
),
migrations.AddField(
model_name='event',
--- /dev/null
+# Generated by Django 2.1.4 on 2018-12-04 21:46
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('mannschaft', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Merch',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('item', models.CharField(blank=True, max_length=50, null=True)),
+ ('costs', models.FloatField()),
+ ],
+ ),
+ migrations.CreateModel(
+ name='Order',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('quantity', models.IntegerField(default=1)),
+ ('merch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Merch')),
+ ('player', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Player')),
+ ],
+ ),
+ migrations.AddField(
+ model_name='merch',
+ name='orders',
+ field=models.ManyToManyField(blank=True, through='mannschaft.Order', to='mannschaft.Player'),
+ ),
+ ]
+++ /dev/null
-# Generated by Django 2.1.3 on 2018-11-03 01:17
-
-from django.conf import settings
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- migrations.swappable_dependency(settings.AUTH_USER_MODEL),
- ('mannschaft', '0001_initial'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='player',
- name='user',
- field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
- ),
- ]
+++ /dev/null
-# Generated by Django 2.1.3 on 2018-11-03 01:42
-
-from django.conf import settings
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('mannschaft', '0002_player_user'),
- ]
-
- operations = [
- migrations.RenameField(
- model_name='playerstate',
- old_name='game',
- new_name='event',
- ),
- migrations.AddField(
- model_name='event',
- name='state',
- field=models.ManyToManyField(related_name='event_player_state', through='mannschaft.PlayerState', to='mannschaft.Player'),
- ),
- migrations.AddField(
- model_name='team',
- name='trainers',
- field=models.ManyToManyField(related_name='trainers', to='mannschaft.Player'),
- ),
- migrations.AlterField(
- model_name='player',
- name='user',
- field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
- ),
- migrations.AlterField(
- model_name='playerstate',
- name='state',
- field=models.CharField(choices=[('y', 'Ja'), ('n', 'Nein'), ('p', 'Vielleicht')], max_length=1),
- ),
- ]
--- /dev/null
+# Generated by Django 2.1.4 on 2018-12-04 22:48
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('mannschaft', '0002_auto_20181204_2246'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='player',
+ name='teams',
+ ),
+ ]
+++ /dev/null
-# Generated by Django 2.1.3 on 2018-11-03 14:01
-
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('mannschaft', '0003_auto_20181103_0242'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='event',
- name='location',
- field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Location'),
- ),
- migrations.AlterField(
- model_name='event',
- name='optional',
- field=models.TextField(blank=True, null=True),
- ),
- migrations.AlterField(
- model_name='event',
- name='state',
- field=models.ManyToManyField(blank=True, null=True, related_name='event_player_state', through='mannschaft.PlayerState', to='mannschaft.Player'),
- ),
- migrations.AlterField(
- model_name='event',
- name='tasks',
- field=models.ManyToManyField(blank=True, null=True, through='mannschaft.Task', to='mannschaft.Player'),
- ),
- migrations.AlterField(
- model_name='game',
- name='score_opponent',
- field=models.IntegerField(blank=True, null=True),
- ),
- migrations.AlterField(
- model_name='game',
- name='score_team',
- field=models.IntegerField(blank=True, null=True),
- ),
- migrations.AlterField(
- model_name='location',
- name='additional',
- field=models.CharField(blank=True, max_length=100, null=True),
- ),
- migrations.AlterField(
- model_name='location',
- name='city',
- field=models.CharField(blank=True, max_length=100, null=True),
- ),
- migrations.AlterField(
- model_name='location',
- name='street',
- field=models.CharField(blank=True, max_length=100, null=True),
- ),
- migrations.AlterField(
- model_name='location',
- name='zip',
- field=models.IntegerField(blank=True, null=True),
- ),
- migrations.AlterField(
- model_name='player',
- name='birthdate',
- field=models.DateField(blank=True, null=True),
- ),
- migrations.AlterField(
- model_name='player',
- name='dsvid',
- field=models.IntegerField(blank=True, null=True),
- ),
- migrations.AlterField(
- model_name='playerstate',
- name='reason',
- field=models.CharField(blank=True, max_length=180, null=True),
- ),
- migrations.AlterField(
- model_name='team',
- name='max_age',
- field=models.IntegerField(blank=True, default=999, null=True),
- ),
- migrations.AlterField(
- model_name='team',
- name='min_age',
- field=models.IntegerField(blank=True, default=0, null=True),
- ),
- ]
+++ /dev/null
-# Generated by Django 2.1.3 on 2018-11-03 14:03
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('mannschaft', '0004_auto_20181103_1501'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='event',
- name='state',
- field=models.ManyToManyField(blank=True, related_name='event_player_state', through='mannschaft.PlayerState', to='mannschaft.Player'),
- ),
- migrations.AlterField(
- model_name='event',
- name='tasks',
- field=models.ManyToManyField(blank=True, through='mannschaft.Task', to='mannschaft.Player'),
- ),
- ]
+++ /dev/null
-# Generated by Django 2.1.3 on 2018-11-03 14:05
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('mannschaft', '0005_auto_20181103_1503'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='team',
- name='players',
- field=models.ManyToManyField(blank=True, to='mannschaft.Player'),
- ),
- migrations.AlterField(
- model_name='team',
- name='trainers',
- field=models.ManyToManyField(blank=True, related_name='trainers', to='mannschaft.Player'),
- ),
- ]
from django.db import models
from django.contrib.auth.models import User
+from django.db.models.signals import post_save
+from django.dispatch import receiver
# Create your models here.
class Player(models.Model):
- name = models.CharField(max_length=50)
- firstname = models.CharField(max_length=50)
birthdate = models.DateField(blank=True, null=True)
dsvid = models.IntegerField(blank=True, null=True)
- user = models.OneToOneField(User, null=True, on_delete=models.SET_NULL)
+ user = models.OneToOneField(User, on_delete=models.CASCADE)
def __str__(self):
- return self.name + ', ' + self.firstname
- # ForeignKey(User, null=True, on_delete=models.SET_NULL)
+ if not self.user.first_name and not self.user.last_name:
+ return self.user.username
+ return self.user.first_name + ', ' + self.user.last_name
+
+
+@receiver(post_save, sender=User)
+def create_player(sender, instance, created, **kwargs):
+ if created:
+ Player.objects.create(user=instance)
+
+
+@receiver(post_save, sender=User)
+def save_player(sender, instance, **kwargs):
+ instance.player.save()
class Team(models.Model):
event = models.ForeignKey(Event, on_delete=models.CASCADE)
state = models.CharField(max_length=1, choices=ANSWERS)
reason = models.CharField(max_length=180, blank=True, null=True)
+
+
+class Merch(models.Model):
+ item = models.CharField(max_length=50, blank=True, null=True)
+ costs = models.FloatField()
+ orders = models.ManyToManyField(Player, through='Order', blank=True)
+
+
+class Order(models.Model):
+ player = models.ForeignKey(Player, on_delete=models.CASCADE)
+ merch = models.ForeignKey(Merch, on_delete=models.CASCADE)
+ quantity = models.IntegerField(default=1)
--- /dev/null
+{% block content %}
+<h1>Mannschaftsverwaltung</h1>
+{% endblock %}
--- /dev/null
+{% if player %}
+ <p>Willkommen {{ player }}</p>
+ {% if teams %}
+ <ul>
+ {% for team in teams %}
+ <li><a href="/mannschaft/teams/{{ team.id }}/">{{ team.name }}</a></li>
+ {% endfor %}
+ </ul>
+ {% else %}
+ <p>Not registered for any team</p>
+ {% endif %}
+{% else %}
+ <p>register as player</p>
+{% endif %}
+
--- /dev/null
+{% extends "base.html" %}
+
+{% block content %}
+
+{% if form.errors %}
+<p>Your username and password didn't match. Please try again.</p>
+{% endif %}
+
+{% if next %}
+ {% if user.is_authenticated %}
+ <p>Your account doesn't have access to this page. To proceed,
+ please login with an account that has access.</p>
+ {% else %}
+ <p>Please login to see this page.</p>
+ {% endif %}
+{% endif %}
+
+<form method="post" action="{% url 'login' %}">
+{% csrf_token %}
+<table>
+<tr>
+ <td>{{ form.username.label_tag }}</td>
+ <td>{{ form.username }}</td>
+</tr>
+<tr>
+ <td>{{ form.password.label_tag }}</td>
+ <td>{{ form.password }}</td>
+</tr>
+</table>
+
+<input type="submit" value="login">
+<input type="hidden" name="next" value="{{ next }}">
+</form>
+
+{# Assumes you setup the password_reset view in your URLconf #}
+<p><a href="{% url 'password_reset' %}">Lost password?</a></p>
+
+{% endblock %}
from . import views
urlpatterns = [
- path('', views.index, name='index'),
+ path('', views.player_overview, name='player_overview'),
+ path('teams/', views.teams, name='teams'),
+ path('teams/<int:team_id>/', views.team_details, name='team_detail'),
]
from django.shortcuts import render
from django.http import HttpResponse
+from django.contrib.auth.models import User
+from django.contrib.auth.decorators import login_required
+from .models import Player, Team
-def index(request):
- return HttpResponse("Mannschaftsverwaltung")
+
+@login_required()
+def player_overview(request):
+ # template = loader.get_template('mannschaft/index.html')
+ # show = "Mannschaftsverwaltung für %s" % request.user
+ context = {'teams': request.user.player.team_set.all(),
+ 'player': request.user.player}
+ #for p in Player:
+ #if p.user == request.user:
+ #context['player'] = p
+ #break
+
+ return render(request, 'mannschaft/player_overview.html', context)
+ # return HttpResponse(show)
+
+
+@login_required()
+def teams(request):
+ return HttpResponse("Teams Overview")
+
+
+@login_required()
+def team_details(request, team_id):
+ return HttpResponse("Team details for %s" % team_id)