Django --models.py and admin.py

Purpose

In this article, the goal is to display the information defined in the models.py file on the management screen by loading it into the admin.py file. Below, as an example, let's define only the name of the profile as a model.

Creation of models.py and reflection in database

apps/models.py


from django.db import models

class Profile(models.Model):
  name = models.CharField(max_length=100)

I made a model called'Profile'in this way.

Reflection in database

$ python manage.py makemigrations

make migrations is an image that creates blueprints. When you do this, it will notify you if an error is detected before it is reflected in the database.

$ python manage.py migrate

migrate is a command used to reflect in the database based on the file created by makemigrations.

This completes the model creation!

Load into admin.py file

apps/admin.py


from django.contrib import admin
from .models import Profile

admin.site.register(Profile)

Register the model with admin.site.register ().

Now you can display Profile on the management screen!

Recommended Posts

Django --models.py and admin.py
Install Python 3.7 and Django 3.0 (CentOS)
Django installation and operation check
Django input check and calendar input
django timezone and language settings
Create and list Django models
Organize [Django] commands and roles
[Note] Django project creation and terminology
HTTPS with Django and Let's Encrypt
Django
[Django] Install radio buttons and shape markup
[Django ORM] Difference between values () and only ()
CentOS 6.4 with Python 2.7.3 with Apache with mod_wsgi and Django
Django project structure customization (splitting and structuring)
Edit Django shift table HTML and CSS
Ramen map creation with Scrapy and Django
Best practices for Django views.py and urls.py (?)
Django novice addicted error and solution notes
Resolve Angural JS and Django template conflicts