Ich habe einen Benutzer hinzugefügt, um eine Funktion zum Erstellen von Verschiebungstabellen zu erstellen, aber plötzlich habe ich beschlossen, die Sortierung nach Anzeigereihenfolge zu implementieren.
Ich blieb jedoch hier stecken. Ich habe User und Profil mit User verknüpft, aber ich habe versucht, Vorname und Nachname in User zu erhalten, aber ich konnte sie doch nicht bekommen ...
Schließlich wurde durch Hinzufügen eines Urteils zu HTML unterstützt, ob die ID des Profils und die ID des Benutzers identisch sind. Ich bin neu, aber ich finde es nicht schön ... Ich habe es ungefähr 3 Stunden lang überprüft, es versucht und es erneut überprüft.
Ich habe mein Bestes gegeben (⌒∇⌒)
python:schedule.views.py
from django.shortcuts import render, redirect, HttpResponseRedirect
from shisetsu.models import *
from accounts.models import *
from .models import *
import calendar
import datetime
from datetime import timedelta
from datetime import datetime as dt
from django.db.models import Sum
from django.contrib.auth.models import User
from django.views.generic import FormView, UpdateView
from django.urls import reverse_lazy
from .forms import *
from dateutil.relativedelta import relativedelta
from django.contrib.auth.models import User
# Create your views here.
def homeschedule(request):
from datetime import datetime
now = datetime.now()
return HttpResponseRedirect('/schedule/monthschedule/%s/%s/' % (now.year,now.month,)) #Automatisch zum Schichtbildschirm dieses Monats umleiten
def monthschedulefunc(request,year_num,month_num):
user_list = User.objects.all()
profile_list = Profile.objects.select_related().values().order_by('hyoujijyun')
print(profile_list)
print(user_list)
year, month = int(year_num), int(month_num)
shisetsu_object = Shisetsu.objects.all()
shift_object = Shift.objects.all()
object_list = Schedule.objects.filter(year = year, month = month).order_by('user', 'date')
month_total = Schedule.objects.select_related('User').filter(year = year, month = month).values("user").order_by("user").annotate(month_total_worktime = Sum("day_total_worktime"))
#Ermitteln Sie die Anzahl der Tage im Schichtbereich
enddate = datetime.date(year,month,20)
startdate = enddate + relativedelta(months=-1)
kaisu = enddate - startdate
kaisu = int(kaisu.days)
kikan = str(startdate) +"~"+ str(enddate)
#Machen Sie eine Liste von Daten und Tagen
hiduke = str(startdate)
date_format = "%Y-%m-%d"
hiduke = dt.strptime(hiduke, date_format)
weekdays = ["Mond","Feuer","Wasser","Holz","Geld","Boden","Tag"]
calender_object = []
youbi_object = []
for i in range(kaisu):
hiduke = hiduke + timedelta(days=1)
calender_object.append(hiduke)
youbi = weekdays[hiduke.weekday()]
youbi_object.append(youbi)
kaisu = str(kaisu)
context = {
'year': year,
'month': month,
'kikan': kikan,
'object_list': object_list,
'user_list': user_list,
'shift_object': shift_object,
'calender_object': calender_object,
'youbi_object': youbi_object,
'kaisu': kaisu,
'shisetsu_object': shisetsu_object,
'month_total' : month_total,
'profile_list' : profile_list,
}
return render(request,'schedule/month.html', context)
def scheduleUpdatefunc(request,pk):
Schedule_list = Schedule.objects.get(pk = int(pk))
User_list = User.objects.get(username = Schedule_list.user)
shift_object = Shift.objects.all()
if request.method == 'POST':
form = ScheduleUpdateForm(data=request.POST)
year = Schedule_list.year
month = Schedule_list.month
if form.is_valid():
Schedule_list.shift_name_1 = form.cleaned_data['shift_name_1']
Schedule_list.shisetsu_name_1 = form.cleaned_data['shisetsu_name_1']
Schedule_list.shift_name_2 = form.cleaned_data['shift_name_2']
Schedule_list.shisetsu_name_2 = form.cleaned_data['shisetsu_name_2']
Schedule_list.shift_name_3 = form.cleaned_data['shift_name_3']
Schedule_list.shisetsu_name_3 = form.cleaned_data['shisetsu_name_3']
Schedule_list.shift_name_4 = form.cleaned_data['shift_name_4']
Schedule_list.shisetsu_name_4 = form.cleaned_data['shisetsu_name_4']
Schedule_list.day_total_worktime = form.cleaned_data['day_total_worktime']
Schedule_list.save()
return HttpResponseRedirect('/schedule/monthschedule/%s/%s/' % (year,month,))
else:
item = {
"shift_name_1":Schedule_list.shift_name_1,
"shisetsu_name_1": Schedule_list.shisetsu_name_1,
"shift_name_2": Schedule_list.shift_name_2,
"shisetsu_name_2": Schedule_list.shisetsu_name_2,
"shift_name_3": Schedule_list.shift_name_3,
"shisetsu_name_3": Schedule_list.shisetsu_name_3,
"shift_name_4": Schedule_list.shift_name_4,
"shisetsu_name_4": Schedule_list.shisetsu_name_4,
}
form = ScheduleUpdateForm(initial=item)
context = {
'form' : form,
'Schedule_list': Schedule_list,
'User_list': User_list,
'shift_object': shift_object,
}
return render(request,'schedule/update.html', context )
'''
#### **`schedule/month.py`**
```html
{% extends 'schedule/base.html' %}
{% block header %}
<ul class="page">
<div align="left">
<li class="previous">
{% ifnotequal month 1 %}
<a href="{% url'schedule:monthschedule' year month | add:'-1'%} "class =" btn-info btn active "> Vormonat </a>
{% else %}
<a href="{% url'schedule:monthschedule' year | add:'-1'12%} "class =" btn-info btn active "> Vormonat </a>
{% endifnotequal %}
</li>
</div>
<div align="right">
<li class="next">
{% ifnotequal month 12 %}
<a href="{% url'schedule:monthschedule' year month | add: '1'%} "class =" btn-info btn active "> Nächster Monat </a>
{% else %}
<a href="{% url'schedule:monthschedule' year | add: '1' 1%} "class =" btn-info btn active "> Nächster Monat </a>
{% endifnotequal %}
</li>
</div>
</ul>
<p>
{% for shisetsu in shisetsu_object %}
<span style="background-color:{{ shisetsu.color }}">{{ shisetsu.name }}</span>
{% endfor %}
</p>
{{ kikan }}
{% for shift in shift_object %}
{% if shift.name! = "Holiday" und shift.name! = "Yes"%}
{{ shift.name }} : {{ shift.start_time | date:"G"}}~{{ shift.end_time | date:"G"}}
{% endif %}
{% endfor %}
{% endblock header %}
{% block content %}
<table class="table table-striped table-bordered">
<thead>
<tr align = "center" class = "info"> <! - Date->
<th rowspan="2"></th>
{% for item in calender_object %}
<th class="day_{{ item.date }}">{{ item.date | date:"d" }}</th>
{% endfor %}
<tr align = "center" class = "info"> <! - Day->
{% for item in youbi_object %}
<th class="day_{{ item.date }}">{{ item }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for profile in profile_list %}
{% for staff in user_list %}
{% if profile.user_id == staff.id %}
<tr align="center">
<th rowspan = "1" class = "staff_name" staff_id = "{{staff.staff_id}}" width = "200"> {{staff.last_name}} {{staff.first_name}} </ th> <! - -staff_id Element wird in js-> verwendet
{% for item in object_list %}
{% if item.user|stringformat:"s" == staff.username|stringformat:"s" %}<!--Wenn der Benutzername der gleiche ist-->
<td class="day" id="s{{ staff.id }}d{{ item.date }}">
{% if item.shift_name_1 != None %}
{% if item.shift_name_1|stringformat:"s" == "Ja" or item.shift_name_1|stringformat:"s" == "Geschlossen" %}
{{ item.shift_name_1 }}
{% else %}
{% for shisetsu in shisetsu_object %}
{% if item.shisetsu_name_1|stringformat:"s" == shisetsu.name|stringformat:"s" %}
<span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_1 }}</span>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% if item.shift_name_2 != None %}
{% if item.shift_name_2|stringformat:"s" == "Ja" or item.shift_name_2|stringformat:"s" == "Geschlossen" %}
{{ item.shift_name_2 }}
{% else %}
{% for shisetsu in shisetsu_object %}
{% if item.shisetsu_name_2|stringformat:"s" == shisetsu.name|stringformat:"s" %}
<span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_2 }}</span>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% if item.shift_name_3 != None %}
{% if item.shift_name_3|stringformat:"s" == "Ja" or item.shift_name_3|stringformat:"s" == "Geschlossen" %}
{{ item.shift_name_3 }}
{% else %}
{% for shisetsu in shisetsu_object %}
{% if item.shisetsu_name_3|stringformat:"s" == shisetsu.name|stringformat:"s" %}
<span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_3 }}</span>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% if item.shift_name_4 != None %}
{% if item.shift_name_4|stringformat:"s" == "Ja" or item.shift_name_4|stringformat:"s" == "Geschlossen" %}
{{ item.shift_name_4 }}
{% else %}
{% for shisetsu in shisetsu_object %}
{% if item.shisetsu_name_4|stringformat:"s" == shisetsu.name|stringformat:"s" %}
<span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_4 }}</span>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
</td>
<tr align="center">
{% for month in month_total %}
{% if month.user == staff.id%} <! - Wenn der Benutzername derselbe ist->
<td><b>{{ month.month_total_worktime }}</b></td>
{% endif %}
{% endfor %}
{% for item in object_list %}
{% if item.user|stringformat:"s" == staff.username|stringformat:"s" %}<!--Wenn der Benutzername der gleiche ist-->
<td class="day" id="s{{ staff.id }}d{{ item.date }}">
<a href="{% url 'schedule:update' item.pk %}">{{ item.day_total_worktime }} </a>
</td>
{% endif %}
{% endfor %}
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</tbody>
</table>
{% endblock content %}
Ich werde von hier aus die Schichterstellungsfunktion aufrufen. Es gibt viele Leute, die für Doppelarbeit arbeiten, also gibt es Leute, die mit Hoffnung hereinkommen, wenn sie hereinkommen, und Leute, die regelmäßig hereinkommen, sich aber an diesem Tag ausruhen.
Also werde ich zunächst versuchen, die Schichtanforderung eingeben zu können.
Recommended Posts