Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python django adding category

// go to the editor terminal 
python manage.py startapp category
// add to settings.py 
INSTALLED_APPS = [
    'category.apps.CategoryConfig',
]
// go to category folder app - models.py 
from django.db import models

//Create your models here.
class Category(models.Model):
    category_name   = models.CharField(max_length=50, unique=True)
    slug            = models.SlugField(max_length=100, unique=True)
    description     = models.TextField(max_length=255, blank=True)
    cat_image       = models.ImageField(upload_to='photos/category', blank=True)

    class Meta:
        verbose_name = 'category'
        verbose_name_plural = 'categories'

    def __str__(self):
        return self.category_name

// go to category folder app - admin.py 
from django.contrib import admin
from .models import Category

//Register your models here.
class CategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('category_name',)}
    list_display = ('category_name', 'slug')

admin.site.register(Category, CategoryAdmin)
// go to editor terminal trying check errors 
python manage.py runserver 
// making migrations 
python manage.py makemigrations
// migrating 
python manage.py migrate
// check to your /admin/ if refelected 
Comment

PREVIOUS NEXT
Code Example
Python :: enum python print all options 
Python :: Openpyxl automatic width 
Python :: sort decreasing python 
Python :: code pandas from url 
Python :: change a coolumn datatype in pandas 
Python :: pd calculations between columns 
Python :: how draw shell in python 
Python :: Python NumPy transpose Function Syntax 
Python :: How to take multiple inputs in one line in python using list comprehension 
Python :: Python use number twice without variable 
Python :: turn off yticklabels 
Python :: number length python 
Python :: speech to text function in python 
Python :: django convert model to csv 
Python :: end without space in python 
Python :: color module python 
Python :: make array consecutive 2 python 
Python :: if condition python 
Python :: python greater than dunder 
Python :: python download images from unsplash 
Python :: python pathlib os module 
Python :: how to find out the max and min date on the basis of property id in pandas 
Python :: how to make python script run forever 
Python :: how to set environment variable in pycharm 
Python :: change creation date filesystem py 
Python :: change folder icon with python 
Python :: change excel value in python 
Python :: scroll to top selenium python 
Python :: Sum of all substrings of a number 
Python :: fillna string 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =