模块 'django.db.models' 没有属性 'FileBrowseField'

Module 'django.db.models' has no attribute 'FileBrowseField'

我想在我的 Django 2.1.1 站点上安装 django-filebrowser-no-grappelli。我已按照 this indications 进行操作,但在过程结束时,当我重新启动服务器时,出现此错误:

header_image = models.FileBrowseField("Image", max_length=200, directory="images/", extensions=[".jpg"], blank=True) AttributeError: module 'django.db.models' has no attribute 'FileBrowseField'

这是我项目的文件:

MODELS.PY

from django.db import models
from django.urls import reverse
from tinymce import HTMLField
from filebrowser.fields import FileBrowseField

class Post(models.Model):
    """definizione delle caratteristiche di un post"""
    title = models.CharField(max_length=70, help_text="Write post title here. The title must be have max 70 characters", verbose_name="Titolo", unique=True)
    short_description = models.TextField(max_length=200, help_text="Write a post short description here. The description must be have max 200 characters", verbose_name="Breve descrizione dell'articolo")
    contents = HTMLField(help_text="Write your post here", verbose_name="Contenuti")
    publishing_date = models.DateTimeField(verbose_name="Data di pubblicazione")
    updating_date = models.DateTimeField(auto_now=True, verbose_name="Data di aggiornamento")
    header_image = models.FileBrowseField("Image", max_length=200, directory="images/", extensions=[".jpg"], blank=True)
    slug = models.SlugField(verbose_name="Slug", unique="True", help_text="Slug is a field in autocomplete mode, but if you want you can modify its contents")

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("singlearticleView", kwargs={"slug": self.slug})

    class Meta:
        verbose_name = "Articolo"
        verbose_name_plural = "Articoli"

VIEWS.PY

from django.shortcuts import render
from .models import Post
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView

class SingleArticle(DetailView):
    model = Post
    template_name = "single_article.html"


class ListArticles(ListView):
    model = Post
    template_name = "list_articles.html"

    def get_queryset(self):
        return Post.objects.order_by('-publishing_date')

URLS.PY

from django.urls import path
from .views import ListArticles, SingleArticle

urlpatterns = [
    path("", ListArticles.as_view(), name="listarticlesView"),
    path("<slug:slug>/", SingleArticle.as_view(), name="singlearticleView"),
]

ADMIN.PY

from django.contrib import admin
from .models import Post

class PostAdmin(admin.ModelAdmin):
    """creazione delle caratteristiche dei post leggibili nel pannello di amministrazione"""
    list_display = ["title", "publishing_date", "updating_date", "id"]
    list_filter = ["publishing_date"]
    search_fields = ["title", "short_description", "contents"]
    prepopulated_fields = {"slug": ("title",)}
    fieldsets = [
                (None, {"fields": ["title", "slug"]}),
                ("Contenuti", {"fields": ["short_description", "contents"]}),
                ("Riferimenti", {"fields": ["publishing_date"]}),
            ]

    class Meta:
        model = Post

admin.site.register(Post, PostAdmin)

URLS.PY 项目

from django.contrib import admin
from django.urls import path, include
from filebrowser.sites import site

urlpatterns = [
    path('admin/filebrowser/', site.urls),
    path('grappelli/', include('grappelli.urls')),
    path('admin/', admin.site.urls),
    path('', include('app4test.urls')),
    path('tinymce/', include('tinymce.urls')),
]

我已经开始了这一切,因为我将使用 TinyMCE 并且需要一个文件浏览器应用程序。当我停用 models.py 项目 运行 中的字符串 header_image 时,很明显,当我尝试上传图像时出现错误。

我哪里弄错了?

您的导入是这样完成的:

from filebrowser.fields import FileBrowseField

但您正在尝试按照以下方式使用该字段:

header_image = models.FileBrowseField(...)

它不是 models 包的一部分,只是没有 models. 部分:

header_image = FileBrowseField(...)