有人能指出我做错了什么吗?我总是会出错:
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)
您使用models.BooleanField作为类别,因此唯一可能的值是True和False。将其更改为models.Charfield,它应该可以工作
这:
category =models.BooleanField(choices=category_choices, default=False)
应该是:
category = models.CharField(choices=category_choices, max_length=255)
相关问题 更多 >
编程相关推荐