Adding subteams to teams
This commit is contained in:
parent
2864593b00
commit
f2b411b60a
20
src/teams/migrations/0003_auto_20170401_2227.py
Normal file
20
src/teams/migrations/0003_auto_20170401_2227.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-04-01 20:27
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('teams', '0002_auto_20170327_2208'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='teammember',
|
||||
old_name='leader',
|
||||
new_name='responsible',
|
||||
),
|
||||
]
|
21
src/teams/migrations/0004_team_sub_team_of.py
Normal file
21
src/teams/migrations/0004_team_sub_team_of.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-04-01 20:32
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('teams', '0003_auto_20170401_2227'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='team',
|
||||
name='sub_team_of',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='teams.Team'),
|
||||
),
|
||||
]
|
|
@ -15,6 +15,7 @@ class Team(CampRelatedModel):
|
|||
camp = models.ForeignKey('camps.Camp')
|
||||
description = models.TextField()
|
||||
members = models.ManyToManyField('auth.User', through='teams.TeamMember')
|
||||
sub_team_of = models.ForeignKey('self', null=True, blank=True, related_name="sub_teams")
|
||||
|
||||
def __str__(self):
|
||||
return '{} ({})'.format(self.name, self.camp)
|
||||
|
@ -32,7 +33,7 @@ class Team(CampRelatedModel):
|
|||
class TeamMember(models.Model):
|
||||
user = models.ForeignKey('auth.User')
|
||||
team = models.ForeignKey('teams.Team')
|
||||
leader = models.BooleanField(default=False)
|
||||
responsible = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return '{} ({})'.format(self.user, self.team)
|
||||
|
|
|
@ -11,4 +11,15 @@ Team: {{ team.name }} | {{ block.super }}
|
|||
|
||||
{{ team.description|unsafecommonmark }}
|
||||
|
||||
|
||||
{% if team.sub_teams.exists %}
|
||||
<hr />
|
||||
<h3>Subteams:</h3>
|
||||
<ul>
|
||||
{% for sub_team in team.sub_teams.all %}
|
||||
<li>{{ sub_team.name }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -8,7 +8,7 @@ Teams | {{ block.super }}
|
|||
{% block content %}
|
||||
|
||||
{% if teams %}
|
||||
<table class="table table-hover table-condensed table-striped">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
|
@ -24,7 +24,27 @@ Teams | {{ block.super }}
|
|||
</a>
|
||||
</td>
|
||||
<td>
|
||||
{% if team.sub_teams.exists %}
|
||||
<div class="pull-left">
|
||||
{% endif %}
|
||||
{{ team.description|unsafecommonmark|truncatewords:50 }}
|
||||
|
||||
{% if team.sub_teams.exists %}
|
||||
<div class="collapse" id="{{ team.slug }}-sub-teams">
|
||||
<strong>Subteams:</strong>
|
||||
<ul>
|
||||
{% for sub_team in team.sub_teams.all %}
|
||||
<li>{{ sub_team.name }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<button class="btn btn-default pull-right" type="button" data-toggle="collapse" data-target="#{{ team.slug }}-sub-teams" aria-expanded="false" aria-controls="collapseExample">
|
||||
Subteams
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -7,7 +7,7 @@ from .models import Team
|
|||
|
||||
class TeamListView(CampViewMixin, ListView):
|
||||
template_name = "team_list.html"
|
||||
model = Team
|
||||
queryset = Team.objects.filter(sub_team_of=None)
|
||||
context_object_name = 'teams'
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue