from django.contrib import admin
-from core.models import StablePart, Bay, Horse, FodderPlan, Misc, IsInBay
+from core.models import StablePart, Bay, Horse, FodderPlan, Misc, IsInBay, HasFodderPlan, HasMisc
# Register your models here.
admin.site.register(StablePart)
admin.site.register(FodderPlan)
admin.site.register(Misc)
admin.site.register(IsInBay)
+admin.site.register(HasFodderPlan)
+admin.site.register(HasMisc)
-# Generated by Django 2.2 on 2019-04-06 22:06
+# Generated by Django 2.2 on 2019-04-16 21:29
from django.db import migrations, models
import django.db.models.deletion
name='Bay',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(blank=True, max_length=120, null=True)),
('bay_number', models.IntegerField()),
],
),
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('fodder', models.TextField()),
- ('valid_since', models.DateTimeField()),
- ('valid_until', models.DateTimeField()),
],
),
+ migrations.CreateModel(
+ name='HasFodderPlan',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('valid_since', models.DateField()),
+ ('valid_until', models.DateField()),
+ ('fodderplan', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.FodderPlan')),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
+ migrations.CreateModel(
+ name='HasMisc',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('valid_since', models.DateField()),
+ ('valid_until', models.DateField()),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
migrations.CreateModel(
name='Horse',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=180)),
+ ('colour', models.CharField(blank=True, max_length=120, null=True)),
+ ('markings', models.CharField(blank=True, max_length=120, null=True)),
],
),
migrations.CreateModel(
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('value', models.TextField()),
- ('valid_since', models.DateTimeField()),
- ('valid_until', models.DateTimeField()),
],
),
migrations.CreateModel(
name='IsInBay',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('in_bay_since', models.DateField()),
- ('in_bay_until', models.DateField()),
+ ('valid_since', models.DateField()),
+ ('valid_until', models.DateField()),
('bay', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Bay')),
('horse', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Horse')),
],
+ options={
+ 'abstract': False,
+ },
),
migrations.AddField(
model_name='horse',
name='bay',
- field=models.ManyToManyField(blank=True, null=True, through='core.IsInBay', to='core.Bay'),
+ field=models.ManyToManyField(blank=True, related_name='horses', through='core.IsInBay', to='core.Bay'),
),
migrations.AddField(
model_name='horse',
name='fodder',
- field=models.ManyToManyField(blank=True, null=True, to='core.FodderPlan'),
+ field=models.ManyToManyField(blank=True, related_name='horses', through='core.HasFodderPlan', to='core.FodderPlan'),
),
migrations.AddField(
model_name='horse',
name='misc_remarks',
- field=models.ManyToManyField(blank=True, null=True, to='core.Misc'),
+ field=models.ManyToManyField(blank=True, related_name='horses', through='core.HasMisc', to='core.Misc'),
+ ),
+ migrations.AddField(
+ model_name='hasmisc',
+ name='horse',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Horse'),
+ ),
+ migrations.AddField(
+ model_name='hasmisc',
+ name='misc',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Misc'),
+ ),
+ migrations.AddField(
+ model_name='hasfodderplan',
+ name='horse',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Horse'),
),
migrations.AddField(
model_name='bay',
name='located_in',
- field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.StablePart'),
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bays', to='core.StablePart'),
),
]
+++ /dev/null
-# Generated by Django 2.2 on 2019-04-07 20:11
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('core', '0001_initial'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='horse',
- name='colour',
- field=models.CharField(blank=True, max_length=120, null=True),
- ),
- migrations.AddField(
- model_name='horse',
- name='markings',
- field=models.CharField(blank=True, max_length=120, null=True),
- ),
- migrations.AlterField(
- model_name='horse',
- name='bay',
- field=models.ManyToManyField(blank=True, through='core.IsInBay', to='core.Bay'),
- ),
- migrations.AlterField(
- model_name='horse',
- name='fodder',
- field=models.ManyToManyField(blank=True, to='core.FodderPlan'),
- ),
- migrations.AlterField(
- model_name='horse',
- name='misc_remarks',
- field=models.ManyToManyField(blank=True, to='core.Misc'),
- ),
- ]
+++ /dev/null
-# Generated by Django 2.2 on 2019-04-07 20:56
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('core', '0002_auto_20190407_2011'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='bay',
- name='name',
- field=models.CharField(blank=True, max_length=120, null=True),
- ),
- ]
+++ /dev/null
-# Generated by Django 2.2 on 2019-04-09 22:42
-
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('core', '0003_bay_name'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='bay',
- name='located_in',
- field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bays', to='core.StablePart'),
- ),
- ]
+++ /dev/null
-# Generated by Django 2.2 on 2019-04-09 22:56
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('core', '0004_auto_20190409_2242'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='horse',
- name='bay',
- field=models.ManyToManyField(blank=True, related_name='in_bay', through='core.IsInBay', to='core.Bay'),
- ),
- ]
+++ /dev/null
-# Generated by Django 2.2 on 2019-04-09 22:58
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('core', '0005_auto_20190409_2256'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='horse',
- name='bay',
- field=models.ManyToManyField(blank=True, related_name='horses', through='core.IsInBay', to='core.Bay'),
- ),
- ]
class StablePart(models.Model):
name = models.CharField(max_length=140)
-
+
def __str__(self):
return 'Stable Part ' + self.name
class Bay(models.Model):
name = models.CharField(max_length=120, null=True, blank=True)
bay_number = models.IntegerField()
- located_in = models.ForeignKey(StablePart, on_delete=models.CASCADE, related_name='bays')
+ located_in = models.ForeignKey(
+ StablePart, on_delete=models.CASCADE, related_name='bays')
def __str__(self):
return (self.name if self.name is not None else '')\
class FodderPlan(models.Model):
fodder = models.TextField()
- valid_since = models.DateTimeField()
- valid_until = models.DateTimeField()
-
- def __str__(self):
- return self.valid_since + ' - ' + self.valid_until
class Misc(models.Model):
value = models.TextField()
- valid_since = models.DateTimeField()
- valid_until = models.DateTimeField()
class Horse(models.Model):
name = models.CharField(max_length=180)
colour = models.CharField(max_length=120, null=True, blank=True)
markings = models.CharField(max_length=120, null=True, blank=True)
- bay = models.ManyToManyField(Bay, through='IsInBay', blank=True, related_name='horses')
- fodder = models.ManyToManyField(FodderPlan, blank=True)
- misc_remarks = models.ManyToManyField(Misc, blank=True)
-
+ bay = models.ManyToManyField(
+ Bay, through='IsInBay', blank=True, related_name='horses')
+ fodder = models.ManyToManyField(
+ FodderPlan, through='HasFodderPlan', blank=True, related_name='horses')
+ misc_remarks = models.ManyToManyField(
+ Misc, through='HasMisc', blank=True, related_name='horses')
+
def __str__(self):
return self.name
-class IsInBay(models.Model):
+class IntervalBasedRelation(models.Model):
+ valid_since = models.DateField()
+ valid_until = models.DateField()
+
+ class Meta:
+ abstract = True
+
+
+class IsInBay(IntervalBasedRelation):
horse = models.ForeignKey(Horse, on_delete=models.CASCADE)
bay = models.ForeignKey(Bay, on_delete=models.CASCADE)
- in_bay_since = models.DateField()
- in_bay_until = models.DateField()
+
+
+class HasFodderPlan(IntervalBasedRelation):
+ fodderplan = models.ForeignKey(FodderPlan, on_delete=models.CASCADE)
+ horse = models.ForeignKey(Horse, on_delete=models.CASCADE)
+
+
+class HasMisc(IntervalBasedRelation):
+ misc = models.ForeignKey(Misc, on_delete=models.CASCADE)
+ horse = models.ForeignKey(Horse, on_delete=models.CASCADE)
--- /dev/null
+// var cards;
+var idToUse;
+
+function generateCards() {
+ // console.log(this.response);
+ // cards += this.response;
+ document.getElementById(idToUse).innerHTML = this.response;
+ // console.log(cards);
+}
+
+function getBayCards(id, stablepartId) {
+ // console.log(bayIds);
+ // cards = '';
+ idToUse = id;
+ const xhr = new XMLHttpRequest();
+ // console.log('loading bay', bay);
+ xhr.open('GET', '/stablepart/'.concat(stablepartId));
+ xhr.addEventListener('load', generateCards);
+ xhr.send();
+
+}
-{% extends 'base.html' %}
-
-{% block title %}{{ object.name }} - {{ block.super }}{% endblock %}
-
-{% block main %}
+<div class="card"><h2>{{ object }}</h2>
+<div>
+{% for bay in object.bays.all %}
<div class="card">
- <h3>{{ object.name }}</h3>
+ <h3>{{ bay }} </h3>
<div>
- <ul>
- {% for bay in object.bays.all %}
- <li><a href="/bay/{{ bay.id }}">{{ bay }}</a></li>
- {% empty %}
- <li>EMPTY</li>
+ {% for inbay in bay.isinbay_set.all %}
+ <div class="card"><h4><button class="text">{{ inbay.horse }}</button></h4>
+ <div>{{ inbay.valid_since }} bis {{ inbay.valid_until }}</div>
+ </div>
{% endfor %}
- </ul>
</div>
</div>
-{% endblock %}
+{% endfor %}
+</div>
+</div>
<div id="bays"></div>
{% endblock %}
{% block nav %}
-<ul>
+{% load static %}
+<script src="{% static 'core/dynamic_card_load.js' %}"></script>
{% for sp in object_list %}
- <li><button onclick="getBayCards('bays', [{% for bay in sp.bays.all %} {{bay.id}}, {% endfor %}])">{{ sp }}</button></li>
+ {% if forloop.first %}
+ <script>getBayCards('bays', {{ sp.pk }});</script>
+ {% endif %}
+ <button class="block" onclick="getBayCards('bays', {{sp.pk}})">{{ sp }}</button>
{% empty %}
- <li>No Stable yet</li>
+ No Stable yet
{% endfor %}
-</ul>
{% endblock %}
body {
display: grid;
grid-template-columns: 15em 1fr;
- grid-template-rows: 1fr 6fr 1fr;
+ grid-template-rows: 1fr 6fr 2fr;
grid-template-areas:
"header header"
"nav main"
div#header {
grid-area: header;
- border: 1px solid red;
+ /* border: 1px solid red; */
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+ background: rebeccapurple;
+ color: lightgrey;
+}
+
+div#header > div#headertitle {
+ font-size: xx-large;
+ font-weight: bolder;
+ vertical-align: middle;
+ /* background: magenta; */
+ text-align: center;
}
div#nav {
grid-area: nav;
- border: 1px solid red;
+ /* border: 1px solid red; */
}
div#main {
grid-area: main;
- border: 1px solid red;
+ overflow-y: auto;
+ /* border: 1px solid red; */
}
div#footer {
- grid-area: footer
- border: 1px solid red;
+ grid-area: footer;
+ border-top: 2px solid darkgrey;
}
div.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
border-radius: 5px;
+ margin: 5px 0;
}
div.card:hover {
margin: 0;
border-bottom: 1px solid lightgrey;
}
+
+button.block {
+ display: block;
+ width: 100%;
+ border: none;
+ background-color: darkcyan;
+ padding: 10px 20px;
+ cursor: pointer;
+ text-align: center;
+ color: white;
+ margin: 5px 0;
+}
+
+button.block:hover {
+ background-color: darkslategrey;
+}
+
+button.text {
+ border: none;
+ background-color: inherit;
+ padding: 10px 20px;
+ cursor: pointer;
+ display: inline-block;
+ color: black;
+ font-size: inherit;
+ font-style: inherit;
+ font-weight: inherit;
+}
+
+button.text:hover {
+ background: #eee;
+}
+
+button {
+ transition-duration: 0.4s;
+ overflow: hidden;
+ cursor: pointer;
+}
+
+button:after {
+ content: "";
+ background: #a00;
+ /* display: block; */
+ /* position: absolute; */
+ padding-top: 300%;
+ /* padding-left: 350%; */
+ /* margin-left: -20px!important; */
+ /* margin-top: -120%; */
+ opacity: 0;
+ transition: all 0.8s;
+}
+
+button:active:after {
+ padding: 0;
+ /* margin: 0; */
+ opacity: 1;
+ transition: 0s;
+}
-function setMainCards( id, cards ) {
- document.getElementById(id).innerHTML = cards;
-
-}
-
-function generateCard( title, content ) {
+function generateCard(title, content) {
return '<div class="card"><h3>'.concat(title).concat('</h3><div>').concat(content).concat('</div></div>');
}
return generateCard(card.title, card.content);
}
-function generateCards() {
- // console.log(this.response);
- cards += this.response;
- document.getElementById('bays').innerHTML = cards;
- // console.log(cards);
-}
-var cards;
-function getBayCards(id, bayIds) {
- // console.log(bayIds);
- cards = '';
-
- for (const bay of bayIds) {
- const xhr = new XMLHttpRequest();
- // console.log('loading bay', bay);
- xhr.open('GET', '/bay/'.concat(bay));
- xhr.addEventListener('load', generateCards);
- xhr.send();
- }
-}
+
<title>{% block title %} Stable Management {% endblock %}</title>
</head>
<body>
- <div id="header">{% block header %}<div class="card"><h1>Stable Management</h1><div>content</div></div>{% endblock %}</div>
+ <div id="header">{% block header %}<div id="headertitle">Stable Management</div>{% endblock %}</div>
<div id="nav">{% block nav %}nav{% endblock %}</div>
<div id="main">{% block main %}{% endblock %}</div>
<div id="footer">{%block footer %}footer{% endblock %}</div>