第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

Django 中的自動(dòng)完成字段

Django 中的自動(dòng)完成字段

神不在的星期二 2022-12-27 16:36:33
嘗試在 Django 中設(shè)置 autocomplete_fields。我有以下型號:from django.db import models class Genre(models.Model):   title = models.CharField(max_length=255)class Movie(models.Model):  title = models.CharField(max_length=255)  year = models.IntegerField()  time = models.CharField(max_length=255)  director = models.CharField(max_length=255)  genre = models.ManyToManyField(Genre)    image = models.ImageField(upload_to='images/')  actors = models.TextField()  summary = models.TextField()admin.py:from django.contrib import adminfrom .models import Movie, Genreclass SettingAdmin(admin.ModelAdmin):  search_fields = ['genre']class MovieAdmin(admin.ModelAdmin):  autocomplete_fields = ['genre']admin.site.register(Movie, MovieAdmin)admin.site.register(Genre)錯(cuò)誤信息:Exception in thread django-main-thread:Traceback (most recent call last):File "c:\users\ali\appdata\local\programs\python\python38\lib\threading.py", line 932, in _ bootstrap_innerself.run()File "c:\users\ali\appdata\local\programs\python\python38\lib\threading.py", line 870, in runself._target(*self._args, **self._kwargs)File "C:\Users\Ali\Desktop\cinemaEnv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapperfn(*args, **kwargs)File "C:\Users\Ali\Desktop\cinemaEnv\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_runself.check(display_num_errors=True)File "C:\Users\Ali\Desktop\cinemaEnv\lib\site-packages\django\core\management\base.py", line 441, in checkraise SystemCheckError(msg)django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:ERRORS:<class 'movies.admin.MovieAdmin'>: (admin.E040) ModelAdmin must define "search_fields", because it's  referenced by MovieAdmin.autocomplete_fields.我使用 django.contrib.auth.models 中的用戶模型嘗試此代碼并且它有效。我使用 django.contrib.auth.models 中的用戶模型嘗試此代碼并且它有效。
查看完整描述

1 回答

?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊

正如錯(cuò)誤消息所說:

您需要在Genre admin 中定義“search_fields”,因?yàn)槟褂胊utocomplete_fields = ['genre'],

并且不要忘記向其注冊 Genre 模型。


class GenreAdmin(admin.ModelAdmin):

  search_fields = ['title']


admin.site.register(Genre, GenreAdmin)


查看完整回答
反對 回復(fù) 2022-12-27
  • 1 回答
  • 0 關(guān)注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號