basename - The base to use for the URL names that are created. If unset the basename will be automatically generated based on the queryset attribute of the viewset, if it has one. Note that if the viewset does not include a queryset attribute then you must set basename when registering the viewset.
(0.000) SELECT @@SQL_AUTO_IS_NULL; args=None
(0.000) SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; args=None
(0.005) SELECT COUNT(*) AS `__count` FROM `api_Test` WHERE `api_Test`.`count_time` >= '2021-02-21 08:11:17.385916'; args=('2021-02-21 08:11:17.385916',)
(0.001) SELECT `api_Test`.`id`, `api_Test`.`access_count`, `api_Test`.`count_time` FROM `api_Test` WHERE `api_Test`.`count_time` >= '2021-02-21 08:11:17.385916' ORDER BY `api_Test`.`count_time` ASC LIMIT 10; args=('2021-02-21 08:11:17.385916',)
/Users/huatai/onesre_venv3/lib/python3.9/site-packages/django/db/models/fields/__init__.py:1367: RuntimeWarning: DateTimeField Test.count_time received a naive datetime (2021-02-21 03:50:13.414188) while time zone support is active.
warnings.warn("DateTimeField %s received a naive datetime (%s)"
System check identified no issues (0 silenced).
from datetime import datetime
naive_dt = datetime.now()
naive_utc_dt = datetime.utcnow()
from datetime import datetime, timezone
utc_dt = datetime.now(timezone.utc) # UTC time
dt = utc_dt.astimezone() # local time
from django.utils import timezone
timezone.localtime(timezone.now())
now = timezone.now()
# When time zone support is enabled, convert "now" to the user's time
# zone so Django's definition of "Today" matches what the user expects.
if timezone.is_aware(now):
now = timezone.localtime(now)
import datetime
from django.contrib import admin
from django.contrib.admin.filters import DateFieldListFilter
from django.utils.translation import gettext_lazy as _
class MyDateTimeFilter(DateFieldListFilter):
def __init__(self, *args, **kwargs):
super(MyDateTimeFilter, self).__init__(*args, **kwargs)
now = timezone.now()
# When time zone support is enabled, convert "now" to the user's time
# zone so Django's definition of "Today" matches what the user expects.
if timezone.is_aware(now):
now = timezone.localtime(now)
today = now.date()
self.links += ((
(_('Next 7 days'), {
self.lookup_kwarg_since: str(today),
self.lookup_kwarg_until: str(today + datetime.timedelta(days=7)),
}),
))
class BookAdmin(admin.ModelAdmin):
list_filter = (
('published_at', MyDateTimeFilter),
)
Waiting for apps ready_event.
=========
Test ME
time_threshold: 2021-02-21 21:23:25.401293
=========
Apps ready_event triggered. Sending autoreload_started signal.
...
from datetime import datetime, timedelta
from rest_framework import viewsets
from rest_framework.response import Response
class TestViewSet(viewsets.ModelViewSet):
serializer_class = TestSerializer
def list(self, request):
time_threshold = datetime.now() - timedelta(minutes = 1)
queryset = Test.objects.all().filter(count_time__gte = time_threshold).order_by('count_time')
return Response(serializer_class.data)
...
AssertionError: `basename` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.