请更正以下错误,我无法在模型中添加数据

2024-04-20 12:03:52 发布

您现在位置:Python中文网/ 问答频道 /正文

有人能指出我做错了什么吗?我总是会出错:

enter image description hereenter image description here

model.py

from django.db import models
from datetime import datetime 
from ckeditor.fields import RichTextField
# Create your models here.

class Youtuber(models.Model):

    crew_choices = (
        ('solo','solo'),
        ('small','small'),
        ('large','large'),
    )

    camera_choices = (
        ('canon','canon'),
        ('nikon','nikon'),
        ('sony','sony'),
        ('red','red'),
        ('fuji','fuji'),
    )

    category_choices = (
        ('code','code'),
        ('mobile_review','mobile_review'),
        ('vlogs','vlogs'),
        ('comedy','comedy'),
        ('gaming','gaming'),
    )

    name=models.CharField(max_length=254)
    price = models.IntegerField()
    photo = models.ImageField(upload_to='media/ytubers/%Y/%m')
    video_url = models.CharField(max_length=255)
    description = RichTextField()
    city =models.CharField(max_length=255)
    age =models.IntegerField()
    height = models.IntegerField()
    crew =models.CharField(choices=crew_choices, max_length=255)
    camera_type =models.CharField(choices=camera_choices, max_length=255)
    subs_count =models.CharField(max_length=255)
    category =models.BooleanField(choices=category_choices, default=False)
    is_featured =models.BooleanField(default=False)
    created_date =models.DateTimeField(default = datetime.now, blank=True )

管理员

from django.contrib import admin
from .models import Youtuber
from django.utils.html import format_html
# Register your models here.

class YtAdmin(admin.ModelAdmin):

    # def myphoto(self,object):
    #        return format_html('<img src="{}" width="40" />.format(object.photo.url)')



    list_display = ('id','name','subs_count','is_featured')
    search_fields = ('name','camera_type')
    list_filter = ('city','camera_type')
    list_dispaly_link = ('id','name')
    list_editable = ('is_featured',)


admin.site.register(Youtuber,YtAdmin)

Tags: djangonamefromimportdatetimemodelslengthmax