Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Forth step - Creating new app

// 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/
// ============================================
Comment

PREVIOUS NEXT
Code Example
Python :: python specify multiple possible types 
Python :: exception: python in worker has different version 3.7 than that in driver 3.8, pyspark cannot run with different minor versions. please check environment variables pyspark_python and pyspark_driver_python are correctly set. 
Python :: how to test webhook in python.py 
Python :: flask int route 
Python :: pyqt5 cursor starting on a widget 
Python :: seewave python 
Python :: pandascheck if two columns match and populate new column 
Python :: python deep setter 
Python :: how to identify set list and tuple in python 
Python :: Update only values in python 
Python :: indexers in python 
Python :: pandas mask string contains 
Python :: treesitter python languages 
Python :: multiple channel creating command in discord.py 
Python :: sklearn mahalanobis distance 
Python :: add legend to px.choropleth map python 
Python :: converting 1d array into upper triangular 
Python :: 2d vector in python 
Python :: splitting x,y using iloc 
Python :: configparser error reading relative file path 
Python :: fast comand exit python windows 
Python :: dask dataframe csv tutorial 
Python :: pythongalaxy.com 
Python :: the process of delivery of any desisered data 
Python :: import all models 
Python :: zen of python source code 
Python :: convert python to java online 
Python :: Count total number of null, isna sum python 
Python :: mongoengine ObjectIdField 
Python :: How to make boxplot using seaborne 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =