Django Admin
Prerequites 1
settings.py - /path/projectdir/theproject
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test',
'USER': 'test',
'PASSWORD': 'pwd',
'HOST':'localhost',
'PORT':'3306',
}
}
...
STATIC_ROOT = '/path/projectdir/static/'
...
CSRF_TRUSTED_ORIGINS = ['https://theproject.activetechsystems.com']
...
$ python manage.py migrate
Prerequites 2
Create & Setup static directory
# Create static dir
$ cd /path/projectdir
$ mkdir static
$ python manage.py collectstatic -link --noinput
$ python manage.py createsuperuser
# Go to browser:
# https://theroject.activetechsystems.com/admin
Usage Example
For Students model to appear in the admin
admin.py - /path/projectdir/theapp
from django.contrib import admin
from .models import Students
admin.site.register(Students)
List of students with names to appear in the admin
models.py add __str__ function - /path/projectdir/theapp
from django.db import models
class Students(models.Model):
id = models.BigAutoField(primary_key=True)
name = models.CharField(max_length=255)
email = models.CharField(unique=True, max_length=255)
gender = models.CharField(max_length=255)
admission_date = models.DateField()
age = models.IntegerField(default=0)
percent = models.FloatField()
class Meta:
managed = False
db_table = 'students'
def __str__(self):
return self.name