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、查看结果

相关推荐
维度攻城狮3 小时前
ros2参数通信案例
开发语言·windows·python·ros2·参数通信
深圳佛手3 小时前
不用智能体开发框架,如何调用工具?
前端·python
清水白石0083 小时前
Python 与尾递归:为何不优化?如何优雅绕过?
开发语言·python
王大傻09283 小时前
使用python for循环与ord() + chr()实现字符串加密
开发语言·python
540_5404 小时前
ADVANCE Day35
人工智能·python·深度学习
ELI_He9994 小时前
hyperf auth模块
后端·php
郑泰科技4 小时前
python深度学习报错:Original error was: No module named ‘numpy.core._multiarray_umath‘
python·深度学习·numpy
不要em0啦4 小时前
从0开始学python:函数与数据容器
开发语言·python
无限码力5 小时前
华为OD技术面真题 - Python开发 -3
python·华为od·华为od技术面真题·华为od面试八股文·华为od面试python八股文·华为od技术面八股真题
0思必得05 小时前
[Web自动化] Requests模块响应的内容
运维·前端·python·自动化·html·web自动化