Forth Step - Création d'une nouvelle application
// creating a new app
python manage.py startapp category
// go to settings.py - followin code below
INSTALLED_APPS = [
'category',
]
// creating MODEL - go to ( category ) foler - models.py
from django.db import models
class Category(models.Model):
category_name = models.CharField(max_length=50, unique=True)
slug = models.CharField(max_length=100, unique=True)
description = models.TextField(max_length=255, blank=True)
cat_image = models.ImageField(upload_to='photos/category', blank=True)
// use for admin naming
class Meta:
verbose_name = 'category'
varbose_name_plural = 'categories'
def __str__(self):
return self.category_name
// go to category folder - admin.py - paste the codes below
from django.contrib import admin
from .models import Category
admin.site.register(Category)
// go to terminal type codes below:
python manage.py makemigrations
// if successful install the pillow like codes below
pip install pillow
// run the code below again
python manage.py makemigrations
// to check - go to category - migrations you will see the file like below
0001_initial.py
// nwo let's run migrations files
python manage.py migrate
// make sure the spelling is correct
// creating admin superusers
// if you are using GITBASH terminal use the code below
winpty python manage.py createsuperuser
// if you are using EDITOR TERMINAL use the code below
python manage.py createsuperuser
// run the server
python manage.py runserver
// go to the admin page to login
http://127.0.0.1:8000/admin/login/?next=/admin/
// ============================================
BenLeolam