Здравствуйте, я использую даты для поисковых запросов. Но я получаю ошибку во время выполнения.
RuntimeWarning: DateTimeField Jobs.job_created_on получил наивную дату / время (2019-01-17 00:00:00), пока активна поддержка часового пояса.
Views.py
class JobListView(LoginRequiredMixin, generic.TemplateView):
template_name = 'admin/jobs/job.html'
def get(self, request, *args, **kwargs):
context = super(JobListView, self).get_context_data(**kwargs)
if 'status' in request.GET:
form = JobSearchForm(request.GET)
if form.is_valid():
status = form.cleaned_data['status']
start_date = form.cleaned_data['start_date']
end_date = form.cleaned_data['end_date']
company = self.request.user.userprofile.user_company
lookups = (Q(job_company=self.request.user.userprofile.user_company) )
if start_date:
lookups = lookups | Q(job_created_on__gte=start_date)
if end_date:
lookups = lookups | Q(job_created_on__lte=end_date)
jobs=Jobs.objects.exclude(job_is_deleted = True).filter(lookups)
else:
form = JobSearchForm()
company_name = self.request.user.userprofile.user_company
jobs = Jobs.objects.exclude(
job_is_deleted = True
).filter(
job_company=self.request.user.userprofile.user_company
)
return render(request, self.template_name, {'form': form, 'jobs': jobs})
Forms.py
ACTIVE_CHOICES = (
('AllStatus', 'Select Status'),
('Active', 'Active'),
('InActive', 'Inactive'),
)
class JobSearchForm(forms.Form):
start_date = forms.DateField(label=False)
end_date = forms.DateField(label=False)
status = forms.ChoiceField(choices=ACTIVE_CHOICES, label=False, initial="")
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['start_date'].widget.attrs['placeholder'] = 'Start Date'
self.fields['end_date'].widget.attrs['placeholder'] = 'End Date'
# self.fields['status'].initial = 'Select Status'
self.fields['start_date'].widget.attrs['class'] = 'job_date'
self.fields['end_date'].widget.attrs['class'] = 'job_date'
self.fields['start_date'].required=False
self.fields['end_date'].required=False
Models.py - Работа Моделей
class Jobs(models.Model):
job_created_on = models.DateTimeField(auto_now_add=True)
job_created_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='job_created_bys')
job_updated_on = models.DateTimeField(auto_now=True)
job_updated_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='job_updated_bys')
job_is_deleted = models.BooleanField(default=False)
job_deleted_at = models.DateTimeField(blank=True, null=True)
ACTIVE = 'Active'
INACTIVE = 'Inactive'
JOB_ACTIVE_CHOICES = (
(ACTIVE, 'Active'),
(INACTIVE, 'Inactive'),
)
job_status = models.CharField(
max_length=8,
choices=JOB_ACTIVE_CHOICES,
default=INACTIVE,
)
Почему оно выдает мне предупреждение во время выполнения - RuntimeWarning: DateTimeField Jobs.job_created_on получил наивное время даты (2019-01-17 00:00:00), пока активна поддержка часового пояса.