Подклассы BaseDatabaseOperations могут потребовать метод datetime_extract_sql()
Я работаю над проектом Django, интегрированным с MongoDB в качестве базы данных. Я настроил свои модели для простого сообщения в блоге, представления ( представления на основе функций) и URL, но у меня возникает такая ошибка, когда я хочу добавить сообщение (пока из области администратора):
NotImplementedError at /admin/mongo/post/add/
subclasses of BaseDatabaseOperations may require a datetime_extract_sql() method
models.py
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
# Create your models here.
class PublishedManager(models.Manager):
def get_queryset(self):
return super(PublishedManager, self).get_queryset().filter(status='published')
class Post(models.Model):
STATUS_CHOICES = (
('draft', 'Draft'),
('published', 'Published'),
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250, unique_for_date='publish')
author = models.ForeignKey(
User, on_delete=models.CASCADE, related_name='blog_posts')
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
status = models.CharField(
max_length=10, choices=STATUS_CHOICES, default='draft')
objects = models.Manager()
published = PublishedManager()
class Meta:
ordering = ('-publish',)
verbose_name = 'Post'
verbose_name_plural = 'Posts'
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("mongo:post_detail", args=[self.publish.year, self.publish.month, self.publish.day, self.slug])
views.py
from django.shortcuts import render, get_object_or_404
from .models import Post
# Create your views here.
def post_list(request):
posts = Post.published.all()
return render(request, 'blog\post\list.html', {'posts': posts})
def post_detail(request, year, month, day, post):
post = get_object_or_404(Post, slug=post,
status='published',
publish__year=year,
publish__month=month,
publish__day=day)
return render(request, 'blog/post/detail.html', {'post': post})