[PYTHON] django table creation

Last time, I even created an app. Today, let's start the server easily and check that the server starts up and is displayed properly.

First of all, in order to call the function to the URL of the staff application, import Views and make the function called hello called when there is hello in the URL.

python:staff.url.py


from django.urls import path, include
from .views import hello

urlpatterns = [
    path('hello/', hello, name = "hello"),
]

There are some imports that you don't need, but for the time being, we are doing the necessary maintenance to start the server.

Then add the hello function to call to views.py. If there is a request for this hello, write the command to return the next character in the http response.

python:staff.views.py


from django.shortcuts import render
from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello welcome")

In order to return http, import HttpResponse in http is added.

Start the server in the terminal.

Terminal


python3 manage.py runserver

Then the server will start if there is no problem with the settings

Terminal


September 12, 2020 - 20:52:23
Django version 3.0.8, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

image.png

The page was successfully returned in staff / hello as the URL: grin:

Now, I'm going to create a staff table.

python:staff.models.py


class Staff(models.Model):

from django.db import models

    id = models.AutoField(verbose_name='Employee ID',primary_key=True)
    password = models.CharField(verbose_name='password',max_length=20)
    name = models.CharField(verbose_name='Employee name',max_length=20, blank=False, null=True)
    roll = models.CharField(verbose_name='Position',max_length=10, blank=False, null=True)
    nyushabi = models.DateField(verbose_name='Hire date',blank=False, null=True)
    taishabi = models.DateField(verbose_name='Leaving date',blank=False, null=True)
    hyoujijyun = models.IntegerField(verbose_name='Display order',unique=True)
    jikyu = models.IntegerField(verbose_name='Hourly wage',blank=False, null=True)
    delete = models.BooleanField(verbose_name='Delete flag',default=False)
    create_date = models.DateTimeField(verbose_name='Creation date and time', auto_now_add=True)
    create_user = models.IntegerField(verbose_name='Create user', max_length=50, null=True)
    update_date = models.DateTimeField(verbose_name='Update date and time', auto_now=True)
    update_user = models.IntegerField(verbose_name='Update user', max_length=50, null=True)

    def __str__(self):
        return self.name

Still, I thought that the employee ID could be arbitrarily set without duplication, but this time I decided to have it by incrementing the automatic setting. verbose_name is given by the field name where you see it on the management screen.

I feel that there is still a lack of consideration, but next I would like to create the fields described in the database.

Recommended Posts

django table creation
Django shift table shift data creation function completed
Django Python shift table
Django shift creation feature
Django Getting Started: 2_ Project Creation
Rename table columns in Django3
Output table structure in Django
Django
Web application creation with Django
[Note] Django project creation and terminology
django update
Django note 4
Django memorandum
django search
Django installation
Django Summary
Django test
Django # 2 (template)
Django Note 5
Django hands-on
Touch django
django notes
Django Summary
Django basics
Django Shoho
Django defaults
Django Tutorial (Blog App Creation) ⑤ --Article Creation Function
Django + Docker
Schedule table
Django Glossary
Django search
Install Django
File creation
Django: References
Django Tutorial (Blog App Creation) ④ --Unit Test
Excel table creation with Python [Progress management table]
Django Note 1
Edit Django shift table HTML and CSS
Django note 3
Django note 2
Ramen map creation with Scrapy and Django
Django startup
Django notes
Django NullCharField
Django Tutorial (Blog App Creation) ① --Preparation, Top Page Creation
WEB application development using Django [Admin screen creation]
Until Django application creation by terminal (development environment)
Django tutorial summary for beginners by beginners ① (project creation ~)
Django Tutorial (Blog App Creation) ③ --Article List Display
Django Tutorial (Blog App Creation) ⑦ --Front End Complete
Display the Django shift table! Supports 20-day closing