At first, when the administrator receives a notification of the desired shift, register it, and when executing shift creation once a month, first create a schedule from the desired shift, and if there is no shift, shift on the same day of the previous month I will try to put it in.
First of all, the desired shift
schedule/models.py
class KibouShift(models.Model):
id = models.AutoField(verbose_name='Desired shift ID',primary_key=True)
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Employee name')
date = models.DateField(verbose_name='date')
shift_name_1 = models.ForeignKey(Shift, verbose_name='1 shift name', related_name='kibou_shift_name1',on_delete=models.SET_NULL,null= True)
shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='1 facility', related_name='kibou_shisetsu_name1',on_delete=models.SET_NULL,blank=True, null=True)
shift_name_2 = models.ForeignKey(Shift, verbose_name='2 shift name', related_name='kibou_shift_name2',on_delete=models.SET_NULL,blank=True, null=True)
shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='2 facilities', related_name='kibou_shisetsu_name2',on_delete=models.SET_NULL,blank=True, null=True)
shift_name_3 = models.ForeignKey(Shift, verbose_name='3 shift name', related_name='kibou_shift_name3',on_delete=models.SET_NULL,blank=True, null=True)
shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='3 facilities', related_name='kibou_shisetsu_name3',on_delete=models.SET_NULL,blank=True, null=True)
shift_name_4 = models.ForeignKey(Shift, verbose_name='4 shift name', related_name='kibou_shift_name4',on_delete=models.SET_NULL,blank=True, null=True)
shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='4 facilities', related_name='kibou_shisetsu_name4',on_delete=models.SET_NULL,blank=True, null=True)
class Meta:
unique_together = ('user', 'date')
schedule/admin.py
class KibouShiftAdmin(admin.ModelAdmin):
list_display = ('date', 'user')
ordering = [ "date" ]
admin.site.register(KibouShift, KibouShiftAdmin)
schedule/views.py
def kiboulistfunc(request):
KibouShift_list = KibouShift.objects.all().order_by('-date')
User_list = User.objects.all()
shift_object = Shift.objects.all()
context = {
'KibouShift_list': KibouShift_list,
'User_list': User_list,
'shift_object': shift_object,
}
return render(request,'schedule/kiboushift/list.html', context )
class KibouCreate(CreateView):
template_name = 'schedule/kiboushift/create.html'
model = KibouShift
fields = ('user', 'date', 'shift_name_1', 'shisetsu_name_1', 'shift_name_2', 'shisetsu_name_2', 'shift_name_3', 'shisetsu_name_3', 'shift_name_4', 'shisetsu_name_4')
success_url = reverse_lazy('schedule:KibouList')
class KibouUpdate(UpdateView):
template_name = 'schedule/kiboushift/update.html'
model = KibouShift
fields = ('user', 'date', 'shift_name_1', 'shisetsu_name_1', 'shift_name_2', 'shisetsu_name_2', 'shift_name_3', 'shisetsu_name_3', 'shift_name_4', 'shisetsu_name_4')
success_url = reverse_lazy('schedule:KibouList')
class KibouDelete(DeleteView):
template_name = 'schedule/kiboushift/delete.html'
model = KibouShift
fields = ('user', 'date', 'shift_name_1', 'shisetsu_name_1', 'shift_name_2', 'shisetsu_name_2', 'shift_name_3', 'shisetsu_name_3', 'shift_name_4', 'shisetsu_name_4')
success_url = reverse_lazy('schedule:KibouList')
schedule/kiboushift/base.html
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
{% block customcss %}
{% endblock customcss %}
<title>related family</title>
</head>
<body>
{% block header %}
{% endblock header %}
{% block content %}
{% endblock content %}
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
</html>
schedule/kiboushifr/create.py
{% extends 'schedule/kiboushift/base.html' %}
{% block header %}
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4">Desired shift registration</h1>
<p class="lead"></p>
</div>
</div>
{% endblock header %}
{% block content %}
<form action="" method="POST">{% csrf_token %}
{{form.as_p}}
<p><input type="submit" value="Create" class="btn-info btn active">
<a href="{% url 'schedule:KibouList' %}" class="btn-secondary btn active">Return</a></p>
</form>
{% endblock content %}
schedule/kiboushifr/delete.py
{% extends 'schedule/kiboushift/base.html' %}
{% block header %}
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4">Delete desired shift</h1>
<p class="lead"></p>
</div>
</div>
{% endblock header %}
{% block content %}
<form action="" method="POST">{% csrf_token %}
<p>Employee:{{ object.user }}</p>
<p>date:{{ object.date }}</p>
<p>Shift name:{{ object.shift_name_1|default:"" }}</p>
<p>Facility:{{ object.shisetsu_name_1|default:"" }}</p>
<p>Shift name:{{ object.shift_name_2|default:"" }}</p>
<p>Facility:{{ object.shisetsu_name_2|default:"" }}</p>
<p>Shift name:{{ object.shift_name_3|default:"" }}</p>
<p>Facility:{{ object.shisetsu_name_3|default:"" }}</p>
<p>Shift name:{{ object.shift_name_4|default:"" }}</p>
<p>Facility:{{ object.shisetsu_name_4|default:"" }}</p>
<p><input type="submit" value="Delete" class="btn-info btn active">
<a href="{% url 'schedule:KibouList' %}" class="btn-secondary btn active">Return</a></p>
</form>
{% endblock content %}
schedule/kiboushifr/delete.py
{% extends 'schedule/kiboushift/base.html' %}
{% block header %}
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-6">List of desired shifts</h1>
<p class="lead"></p>
<a href="{% url 'schedule:KibouCreate' %}" class="btn-info btn active">sign up</a>
<a href="{% url 'schedule:homeschedule' %}" class="btn-info btn active">Shift table</a>
</div>
</div>
{% endblock header %}
{% block content %}
<table class="table table-striped table-bordered">
<div class='container'>
<thead>
<th>date</th>
<th>Employee name</th>
<th>Hope shift 1</th>
<th>Desired facility 1</th>
<th>Hope shift 2</th>
<th>Desired facility 2</th>
<th>Hope shift 3</th>
<th>Hope shift 3</th>
<th>Hope shift 4</th>
<th>Desired facility 4</th>
</thead>
<tbody>
{% for item in KibouShift_list %}
{% for staff in User_list %}
{% if item.user|stringformat:"s" == staff.username|stringformat:"s" %}
<tr>
<td>
<a href="{% url 'schedule:KibouUpdate' item.pk %}" class="btn btn-info" role="button" aria-pressed="true">Fix</a>
<a href="{% url 'schedule:kibouDelete' item.pk %}" class="btn btn-info" role="button" aria-pressed="true">Delete</a>
{{ item.date }}
</td>
<td >{{ staff.last_name }} {{ staff.first_name }}</td>
<td >{{ item.shift_name_1|default:"" }} </td>
<td >{{ item.shisetsu_name_1|default:"" }}</td>
<td >{{ item.shift_name_2|default:"" }} </td>
<td >{{ item.shisetsu_name_2|default:"" }}</td>
<td >{{ item.shift_name_3|default:"" }} </td>
<td >{{ item.shisetsu_name_3|default:"" }}</td>
<td >{{ item.shift_name_4|default:"" }} </td>
<td >{{ item.shisetsu_name_4|default:"" }}</td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</tbody>
</div>
</table>
{% endblock content %}
schedule/kiboushifr/update.py
{% extends 'schedule/kiboushift/base.html' %}
{% block header %}
{% endblock header %}
{% block content %}
<form action="" method="POST">{% csrf_token %}
<div class="Container">
{{ form.as_p }}
{% csrf_token %}
<p><input class="btn btn-primary" type="submit" value="update">
<a href="{% url 'schedule:KibouList' %}" class="btn-secondary btn active">Return</a></p>
{% for shift in shift_object %}
{% if shift.name != "Closed" and shift.name != "Yes" %}
{{ shift.name }} : {{ shift.start_time }}~{{ shift.end_time }}
{% endif %}
{% endfor %}
</div>
</form>
{% endblock content %}
This completes. Click here for the list
I was able to make it for the time being, but in reality, the administrator can select a person so that he can register himself, but general users can register only for themselves, I wanted to display the Japanese name properly, but it is quite good I didn't go, and I thought I'd bring it to the point where it could work once, so I cut it off!
Since there is no title part above only the correction screen, I will correct it here
schedule/update.html
{% extends 'schedule/kiboushift/base.html' %}
{% block header %}
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4">Desired shift correction</h1>
<p class="lead"></p>
</div>
</div>
{% endblock header %}
{% block content %}
<form action="" method="POST">{% csrf_token %}
<div class="Container">
{{ form.as_p }}
{% csrf_token %}
<p><input class="btn btn-primary" type="submit" value="update">
<a href="{% url 'schedule:KibouList' %}" class="btn-secondary btn active">Return</a></p>
{% for shift in shift_object %}
{% if shift.name != "Closed" and shift.name != "Yes" %}
{{ shift.name }} : {{ shift.start_time }}~{{ shift.end_time }}
{% endif %}
{% endfor %}
</div>
</form>
{% endblock content %}
I was able to fix it! After that, it is necessary to add input assistance and input check. I will implement it again here.
Next, I would like to implement the function to create a shift from the shift request.
Recommended Posts