python(django)之产品后台管理功能实现

1、添加新项目

在命令行输入以下代码

python manage.py startapp prroduct

2、添加路径和代码结构

在新项目目录下admin.py中加入以代码

复制代码
from .models import Product
class ProductAdmin(admin.ModelAdmin):
    list_display = ['product_name', 'product_desc','producter','created_date','id']

admin.site.register(Product)

在models.py中加入以下代码

复制代码
class Product(models.Model):
    product_name = models.CharField('产品名称', max_length=64)
    product_desc = models.CharField('产品描述', max_length=200)
    producter = models.CharField('产品负责人', max_length=200)
    create_time = models.DateTimeField('创建时间', auto_now=True)

    class Meta:
        verbose_name = '产品管理'
        verbose_name_plural = '产品管理'

    def __str__(self):
        return self.product_name

在主项目下的settings.py加入以下代码:

复制代码
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'apitest', 'prroduct',
](加入而不是全部复制,或者替换一下)

3、查看结果

相关推荐
bjxiaxueliang38 分钟前
一文掌握SpringBoot:HTTP服务开发从入门到部署
spring boot·后端·http
多米Domi01139 分钟前
0x3f 第49天 面向实习的八股背诵第六天 过了一遍JVM的知识点,看了相关视频讲解JVM内存,垃圾清理,买了plus,稍微看了点确定一下方向
jvm·数据结构·python·算法·leetcode
人工智能训练6 小时前
【极速部署】Ubuntu24.04+CUDA13.0 玩转 VLLM 0.15.0:预编译 Wheel 包 GPU 版安装全攻略
运维·前端·人工智能·python·ai编程·cuda·vllm
yaoming1686 小时前
python性能优化方案研究
python·性能优化
码云数智-大飞7 小时前
使用 Python 高效提取 PDF 中的表格数据并导出为 TXT 或 Excel
python
biuyyyxxx8 小时前
Python自动化办公学习笔记(一) 工具安装&教程
笔记·python·学习·自动化
极客数模9 小时前
【2026美赛赛题初步翻译F题】2026_ICM_Problem_F
大数据·c语言·python·数学建模·matlab
小鸡吃米…10 小时前
机器学习中的代价函数
人工智能·python·机器学习
Li emily11 小时前
如何通过外汇API平台快速实现实时数据接入?
开发语言·python·api·fastapi·美股
m0_5613596711 小时前
掌握Python魔法方法(Magic Methods)
jvm·数据库·python