"django custom admin list_filter datetime range" Code Answer's
You're definitely familiar with the best coding language Python that developers use to develop their projects and they get all their queries like "django custom admin list_filter datetime range" answered properly. Developers are finding an appropriate answer about django custom admin list_filter datetime range related to the Python coding language. By visiting this online portal developers get answers concerning Python codes question like django custom admin list_filter datetime range. Enter your desired code related query in the search bar and get every piece of information about Python code related question on django custom admin list_filter datetime range.
django custom admin list_filter datetime range
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),
)
Source: stackoverflow.com
All those coders who are working on the Python based application and are stuck on django custom admin list_filter datetime range can get a collection of related answers to their query. Programmers need to enter their query on django custom admin list_filter datetime range related to Python code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about django custom admin list_filter datetime range for the programmers working on Python code while coding their module. Coders are also allowed to rectify already present answers of django custom admin list_filter datetime range while working on the Python language code. Developers can add up suggestions if they deem fit any other answer relating to "django custom admin list_filter datetime range". Visit this developer's friendly online web community, CodeProZone, and get your queries like django custom admin list_filter datetime range resolved professionally and stay updated to the latest Python updates.