We will create an app to create a shift table.
terminal
python3 manage.py startapp schedule
Add the app to your settings.
config/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts.apps.AccountsConfig',
'shisetsu',
'colorfield',
'schedule'
]
We will create a table in the created schedule app.
Shifts should be managed so that A is from 9:00 to 18:00. You may also be able to take it as if you were paid. Therefore, I will try to have it in the text field.
Regarding the schedule, it means that you may enter multiple shifts a day and work at multiple facilities. It has never happened to enter a shift of 3 or more.
Based on that, I will try to make it with the following table.
schedule/models.py
from django.db import models
from shisetsu.models import *
from accounts.models import *
# Create your models here.
class Shift(models.Model):
id = models.IntegerField(verbose_name='Shift ID',primary_key=True)
name = models.CharField(verbose_name='Shift name', max_length=1)
start_time = models.TimeField(verbose_name="Start time")
end_time = models.TimeField(verbose_name="ending time")
wrok_time = models.IntegerField(verbose_name='Working hours')
def __str__(self):
return self.name
class Schedule(models.Model):
id = models.IntegerField(verbose_name='Schedule ID',primary_key=True)
user = models.OneToOneField(User, on_delete=models.CASCADE)
date = models.DateField(verbose_name='date')
shift_id_1= models.ForeignKey(Shift, verbose_name='1 shift name', on_delete=models.CASCADE)
shisetsu_id_1 = models.ForeignKey(Shisetsu, verbose_name='1 facility', on_delete=models.CASCADE)
shift_id_2 = models.ForeignKey(Shift, verbose_name='2 shift name', on_delete=models.CASCADE)
shisetsu_id_2 = models.ForeignKey(Shisetsu, verbose_name='2 facilities', on_delete=models.CASCADE)
shift_id_3 = models.ForeignKey(Shift, verbose_name='3 shift name', on_delete=models.CASCADE)
shisetsu_id_3 = models.ForeignKey(Shisetsu, verbose_name='3 facilities', on_delete=models.CASCADE)
shift_id_4 = models.ForeignKey(Shift, verbose_name='4 shift name', on_delete=models.CASCADE)
shisetsu_id_4 = models.ForeignKey(Shisetsu, verbose_name='4 facilities', on_delete=models.CASCADE)
I couldn't do this
2 to 3 hours to check this This is the migration.
schedule/models.py
from django.db import models
from shisetsu.models import *
from accounts.models import *
# Create your models here.
class Shift(models.Model):
id = models.IntegerField(verbose_name='Shift ID',primary_key=True)
name = models.CharField(verbose_name='Shift name', max_length=1)
start_time = models.TimeField(verbose_name="Start time")
end_time = models.TimeField(verbose_name="ending time")
wrok_time = models.IntegerField(verbose_name='Working hours')
def __str__(self):
return self.name
class Schedule(models.Model):
id = models.IntegerField(verbose_name='Schedule ID',primary_key=True)
user = models.OneToOneField(User, on_delete=models.CASCADE)
date = models.DateField(verbose_name='date')
shift_name_1 = models.ForeignKey(Shift, verbose_name='1 shift name', related_name='shift_name1',on_delete=models.SET_NULL,null= True)
shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='1 facility', related_name='shisetsu_name1',on_delete=models.SET_NULL,null= True)
shift_name_2 = models.ForeignKey(Shift, verbose_name='2 shift name', related_name='shift_name2',on_delete=models.SET_NULL,null= True)
shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='2 facilities', related_name='shisetsu_name2',on_delete=models.SET_NULL,null= True)
shift_name_3 = models.ForeignKey(Shift, verbose_name='3 shift name', related_name='shift_name3',on_delete=models.SET_NULL,null= True)
shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='3 facilities', related_name='shisetsu_name3',on_delete=models.SET_NULL,null= True)
shift_name_4 = models.ForeignKey(Shift, verbose_name='4 shift name', related_name='shift_name4',on_delete=models.SET_NULL,null= True)
shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='4 facilities', related_name='shisetsu_name4',on_delete=models.SET_NULL,null= True)
I finally finished it… It was long, and if you want to refer to the same table more than once in one table, you have to set each rated_name.
Changed id to auto-increment when entering tentative data
schedule/models.py
from django.db import models
from shisetsu.models import *
from accounts.models import *
# Create your models here.
class Shift(models.Model):
id = models.AutoField(verbose_name='Shift ID',primary_key=True)
name = models.CharField(verbose_name='Shift name', max_length=1)
start_time = models.TimeField(verbose_name="Start time")
end_time = models.TimeField(verbose_name="ending time")
wrok_time = models.IntegerField(verbose_name='Working hours')
def __str__(self):
return self.name
class Schedule(models.Model):
id = models.AutoField(verbose_name='Schedule ID',primary_key=True)
user = models.OneToOneField(User, on_delete=models.CASCADE)
date = models.DateField(verbose_name='date')
shift_name_1 = models.ForeignKey(Shift, verbose_name='1 shift name', related_name='shift_name1',on_delete=models.SET_NULL,null= True)
shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='1 facility', related_name='shisetsu_name1',on_delete=models.SET_NULL,null= True)
shift_name_2 = models.ForeignKey(Shift, verbose_name='2 shift name', related_name='shift_name2',on_delete=models.SET_NULL,null= True)
shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='2 facilities', related_name='shisetsu_name2',on_delete=models.SET_NULL,null= True)
shift_name_3 = models.ForeignKey(Shift, verbose_name='3 shift name', related_name='shift_name3',on_delete=models.SET_NULL,null= True)
shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='3 facilities', related_name='shisetsu_name3',on_delete=models.SET_NULL,null= True)
shift_name_4 = models.ForeignKey(Shift, verbose_name='4 shift name', related_name='shift_name4',on_delete=models.SET_NULL,null= True)
shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='4 facilities', related_name='shisetsu_name4',on_delete=models.SET_NULL,null= True)
As a continuation, I want to display the shift once made correctly, so It's a hassle, but I'm going to make a one-month shift by hand.
When I try to register a schedule, shift is a required input, so I released it.
schedule/models.py
from django.db import models
from shisetsu.models import *
from accounts.models import *
# Create your models here.
class Shift(models.Model):
id = models.AutoField(verbose_name='Shift ID',primary_key=True)
name = models.CharField(verbose_name='Shift name', max_length=1)
start_time = models.TimeField(verbose_name="Start time")
end_time = models.TimeField(verbose_name="ending time")
wrok_time = models.IntegerField(verbose_name='Working hours')
def __str__(self):
return self.name
class Schedule(models.Model):
id = models.AutoField(verbose_name='Schedule ID',primary_key=True)
user = models.OneToOneField(User, on_delete=models.CASCADE)
date = models.DateField(verbose_name='date')
shift_name_1 = models.ForeignKey(Shift, verbose_name='1 shift name', related_name='shift_name1',on_delete=models.SET_NULL,null= True)
shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='1 facility', related_name='shisetsu_name1',on_delete=models.SET_NULL,blank=True, null=True)
shift_name_2 = models.ForeignKey(Shift, verbose_name='2 shift name', related_name='shift_name2',on_delete=models.SET_NULL,blank=True, null=True)
shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='2 facilities', related_name='shisetsu_name2',on_delete=models.SET_NULL,blank=True, null=True)
shift_name_3 = models.ForeignKey(Shift, verbose_name='3 shift name', related_name='shift_name3',on_delete=models.SET_NULL,blank=True, null=True)
shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='3 facilities', related_name='shisetsu_name3',on_delete=models.SET_NULL,blank=True, null=True)
shift_name_4 = models.ForeignKey(Shift, verbose_name='4 shift name', related_name='shift_name4',on_delete=models.SET_NULL,blank=True, null=True)
shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='4 facilities', related_name='shisetsu_name4',on_delete=models.SET_NULL,blank=True, null=True)
Temporarily registered 60 shift data
From here I will create a screen that looks like the shift
Recommended Posts