Create a Django schedule

For the time being, I would like to create a shift creation function, but if there is monthly shift data, implement it first by making it possible to copy it next month, and if it can be developed, the shift conditions of each staff Or, I would like to be able to automatically create shifts for the next month or the current month based on vacation requests and manually correct them.

After copying from the previous month when creating a shift, the shift is edited from the conditions of each staff member. Since this is created in Excel, it is troublesome. I created the creation assistance function in VBA before, but ...

condition is,

・ Regular employees work more than XX hours a month ・ Working only on what day ・ Two people are required to work from XX to XX ・ Staff may work in multiple facilities

I'm going to make it from now on in the form of copying and editing this month when I make it next month. Basically, it seems to be based on the day of the week, so I'd like to put the first Monday in the next Monday.

After implementation, I would like to add useful functions.

I also thought about various tables. If there are multiple shift patterns in a day, I thought about creating it so that it doesn't matter how many it becomes. The technology is still lacking, and from the user's point of view, it doesn't matter whether the back table structure is clean or not. First of all, thinking that it is best to provide something that can be used,

date USER ① Facility shift pattern ② Facility shift pattern ③ Facility shift pattern ④ Facility shift pattern

I will implement it in the form of.

It seems difficult to check the required work of two or more people from XX to XX, so it may be implemented only later (laugh)

I thought that the facility table will be used in various places, so I will create an app for the facility

terminal


python3 manage.py startapp shisetsu

After adding the app, add the app to the setting

config/settigns.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'
]

Specify the model of the facility. Be sure to specify the colors for clarity when displaying basic information and shift tables.

shisetsu/models.py


from django.db import models
from phonenumber_field.modelfields import PhoneNumberField

# Create your models here.
class Shisetsu(models.Model):
    id = models.IntegerField(verbose_name='Facility ID',primary_key=True)
    name = models.CharField(verbose_name='Name of facility', max_length=50)
    adress = models.CharField(verbose_name='Street address', max_length=100)
    tel = PhoneNumberField(verbose_name='phone number', null=True, blank=True) 
    fax = PhoneNumberField(verbose_name='Fax number', null=True, blank=True) 
    color = ColorField(verbose_name='Display color', default='#FF0000')

I'm going to edit on the admin site, so modify admin.py

shisetsu.py


from django.contrib import admin
from .models import Profile

# Register your models here.
admin.site.register(Profile)

Now that the settings are complete, migrate.

terminal


python3 manage.py makemigration

When I implemented it, I got an error.

from phonenumber_field.modelfields import PhoneNumberField

I don't have it, so I think you should import it.

terminal


pip install django-phonenumber-field
pip install phonenumbers

image.png

I think that the installation is completed, so try migrating again.

next,

terminal


color = ColorField(verbose_name='Display color', default='#FF0000')
NameError: name 'ColorField' is not defined

I'm getting an error here.

terminal


pip install django-colorfield

Install and add two to the app in the settings file

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',
    'phonenumber_field.modelfields',
]

And once again, carry out the migration. image.png

It seems to have succeeded.

I will check it from the management screen.

It was displayed, so when I tried to register, I got an error with my phone number.

image.png

I think it's different from the phone number format in Japan ... So fix

python:config.setting.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',
]

Remove phone app

rewrite models

shisetsu.py


from django.db import models
from colorfield.fields import ColorField

# Create your models here.
class Shisetsu(models.Model):
    id = models.IntegerField(verbose_name='Facility ID',primary_key=True)
    name = models.CharField(verbose_name='Name of facility', max_length=50)
    adress = models.CharField(verbose_name='Street address', max_length=100)
    tel = models.CharField(verbose_name='phone number', max_length=20) 
    fax = models.CharField(verbose_name='Fax number', max_length=20) 
    color = ColorField(verbose_name='Display color', default='#FF0000')

This will carry out another migration. You have now saved it.

image.png

Since the facility information does not update the registration so much, we will not create an editing screen.

Recommended Posts

Create a Django schedule
Create a model for your Django schedule
Create a homepage with django
Create a Django login screen
Steps to create a Django project
Create a file uploader with Django
Create a LINE Bot in Django
Create a Python module
Create a dashboard for Network devices with Django!
Create a Bootable LV
Create a one-file hello world application with django
Create a Python environment
How to create a Rest Api in Django
Until you create a new app in Django
Start a Django project
Create Django Todo list
Create a slack bot
A memo to create a virtual environment (venv) before Django
Create a Todo app with Django REST Framework + Angular
I tried to create a table only with Django
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 1 ~
Create a Todo app with the Django REST framework
Create a Todo app with Django ③ Create a task list page
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 2 ~
To myself as a Django beginner (1) --Create a project app--
To myself as a Django beginner (4) --Create a memo app--
Create a Todo app with Django ⑤ Create a task editing function
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 3 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 4 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 5 ~
Create a django environment with docker-compose (MariaDB + Nginx + uWSGI)
Create a Wox plugin (Python)
Create a local pypi repository
Create a function in Python
Create a dictionary in Python
Create an API with Django
Django beginners create simple apps 3
Django beginners create simple apps 1
Create a (simple) REST server
Create ToDo List [Python Django]
Shell to create django project
[Django] Make a pull-down menu
Create a python numpy array
Create a dummy data file
Django beginners create simple apps 2
Create your own Django middleware
Create a heatmap with pyqtgraph
Create a classroom on Jupyterhub
Create a simple textlint server
Create and list Django models
Create a directory with python
Django beginners create simple apps 5
Create a rudimentary ELF packer
Create a shogi game record management app using Django 4 ~ Create View ~
[Django] Create a model suitable for phone numbers / zip codes
Create a web API that can deliver images with Django
Create a Todo app with Django ① Build an environment with Docker
Create a social integration API for smartphone apps with Django
[Python] Create a screen for HTTP status code 403/404/500 with Django
Create a CSV reader in Flask
Create a python GUI using tkinter