mirror of
https://github.com/Findus23/RPGnotes.git
synced 2024-09-08 03:03:44 +02:00
add session and make them unique
This commit is contained in:
parent
97dc9ba75f
commit
c549707bca
6 changed files with 47 additions and 5 deletions
|
@ -1,4 +1,4 @@
|
|||
from django.forms import ModelForm, ModelMultipleChoiceField, CheckboxSelectMultiple
|
||||
from django.forms import ModelForm, ModelMultipleChoiceField, CheckboxSelectMultiple, DateInput
|
||||
|
||||
from days.models import Session, IngameDay
|
||||
|
||||
|
@ -12,3 +12,9 @@ class DayForm(ModelForm):
|
|||
class Meta:
|
||||
model = IngameDay
|
||||
fields = ["day", "description_md", "sessions"]
|
||||
|
||||
|
||||
class SessionForm(ModelForm):
|
||||
class Meta:
|
||||
model = Session
|
||||
fields = ["date"]
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 4.0.5 on 2022-06-19 12:25
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('days', '0005_alter_historicalingameday_options_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='historicalsession',
|
||||
name='date',
|
||||
field=models.DateField(db_index=True, default=datetime.date.today, verbose_name='Date'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='session',
|
||||
name='date',
|
||||
field=models.DateField(default=datetime.date.today, unique=True, verbose_name='Date'),
|
||||
),
|
||||
]
|
|
@ -9,7 +9,7 @@ from common.models import DescriptionModel, HistoryModel
|
|||
|
||||
|
||||
class Session(HistoryModel, models.Model):
|
||||
date = models.DateField(_("Date"), default=date.today)
|
||||
date = models.DateField(_("Date"), default=date.today, unique=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ["-date"]
|
||||
|
|
|
@ -5,6 +5,7 @@ from days import views
|
|||
urlpatterns=[
|
||||
path("", views.list_day_redirect, name="daylist"),
|
||||
path("add", views.DayCreateView.as_view(), name="dayadd"),
|
||||
path("add/session", views.SessionCreateView.as_view(), name="sessionadd"),
|
||||
path("<int:day>", views.DayDetailView.as_view(), name="daydetail"),
|
||||
path("<int:day>/edit", views.DayEditView.as_view(), name="dayedit"),
|
||||
path("<int:day>/delete", views.DayDeleteView.as_view(), name="daydelete"),
|
||||
|
|
|
@ -2,8 +2,8 @@ from django.shortcuts import redirect
|
|||
from django.urls import reverse_lazy
|
||||
from django.views import generic
|
||||
|
||||
from days.forms import DayForm
|
||||
from days.models import IngameDay
|
||||
from days.forms import DayForm, SessionForm
|
||||
from days.models import IngameDay, Session
|
||||
|
||||
|
||||
def list_day_redirect(request, *args, **kwargs):
|
||||
|
@ -34,6 +34,14 @@ class DayCreateView(generic.CreateView):
|
|||
context_object_name = "object"
|
||||
|
||||
|
||||
class SessionCreateView(generic.CreateView):
|
||||
template_name = "loot/edit.jinja"
|
||||
model = Session
|
||||
form_class = SessionForm
|
||||
context_object_name = "object"
|
||||
success_url = reverse_lazy("daylist")
|
||||
|
||||
|
||||
class DayEditView(generic.UpdateView):
|
||||
template_name = "loot/edit.jinja"
|
||||
model = IngameDay
|
||||
|
@ -48,6 +56,7 @@ class DayEditView(generic.UpdateView):
|
|||
return IngameDay.objects.get(day=self.kwargs['day'])
|
||||
|
||||
|
||||
|
||||
class DayDeleteView(generic.DeleteView):
|
||||
template_name = "common/confirm_delete.jinja"
|
||||
model = IngameDay
|
||||
|
|
|
@ -18,7 +18,9 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if request.resolver_match.view_name == "dayedit" %}
|
||||
<a href="{{ url("sessionadd") }}" class="btn btn-secondary">{% trans %}Add Session{% endtrans %}</a>
|
||||
{% endif %}
|
||||
<form method="post" {% if form.is_multipart %}enctype="multipart/form-data"{% endif %}>
|
||||
{% csrf_token %}
|
||||
<input type="submit" class="btn btn-primary"
|
||||
|
|
Loading…
Reference in a new issue