Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python django creating products

// go to terminal 
python manage.py startapp products
// go to settings.py 
INSTALLED_APPS = [
    'products.apps.ProductsConfig',
]
// go to products folder app - models.py 
from django.db import models
from category.models import Category

//Create your models here.
class Product(models.Model):
    product_name    = models.CharField(max_length=200, unique=True)
    slug            = models.SlugField(max_length=200, unique=True)
    description     = models.TextField(max_length=500, blank=True)
    price           = models.IntegerField()
    images          = models.ImageField(upload_to='photo/products')
    stock           = models.IntegerField()
    is_available    = models.BooleanField(default=True)
    category        = models.ForeignKey(Category, on_delete=models.CASCADE)
    created_date    = models.DateTimeField(auto_now_add=True)
    modified_date   = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.product_name

// go to products folder app - admin.py 
from django.contrib import admin
from .models import Product

// Register your models here.
class ProductAdmin(admin.ModelAdmin):
    list_display = ('product_name', 'price', 'stock', 'category', 'modified_date', 'is_available')
    prepopulated_fields = {'slug': ('product_name',)}

admin.site.register(Product, ProductAdmin)
// 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 :: initials of name 
Python :: pyqt5 tab order 
Python :: python you bad 
Python :: restart device micropython 
Python :: does pygame work on python 3.10.1 
Python :: Define the learnable resizer utilities 
Python :: how to add extra str in python?phython,add,append,insert 
Python :: groupby sum and mean 2 columns 
Python :: #Function in python without input method with multiple results: 
Python :: python with statement variables 
Python :: plotly change marker symboly sequence 
Python :: python download from digital ocean spaces boto3 
Python :: list example in python 
Python :: mostFrequentDays python 
Python :: django admin link column display links 
Python :: import 
Python :: how to use displacy 
Python :: intersect and count in sql 
Python :: Insert Multiple Images to Excel with Python 
Python :: ORing two cv mat objects 
Python :: selecting letters in a row 
Python :: call for a last number in series python 
Python :: fix certain parameters during curve fit python lambda 
Python :: addind scheduling of tasks to pyramid python app 
Python :: c++ to python online converter 
Python :: fibonacci series program in python 
Python :: django on_delete rules 
Python :: django is .get lazy 
Python :: trace table python 
Python :: mechanize python #6 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =