Я создаю приложение для работы с персоналом, используя python с Django, у меня возникла проблема с расчетным годом выхода на пенсию сотрудника, например, если сотрудник вводит дату своего рождения, пусть система рассчитает его / ее выход на пенсию год или сколько лет осталось на пенсию. сотрудники уходят на пенсию в 60 лет
Получаю эту ошибку:
TypeError at /staffprofile/profile_entry/
unsupported operand type(s) for -: 'datetime.date' and 'datetime.datetime'
Request Method: POST
Request URL: http://0.0.0.0:8080/staffprofile/profile_entry/
Django Version: 1.8
Exception Type: TypeError
Exception Value:
unsupported operand type(s) for -: 'datetime.date' and 'datetime.datetime'
Exception Location: /home/bakceesay/djangoapps/NAO/venv/src/staffprofile/views.py in profile_entry, line 57
это мой код в views.py
from __future__ import unicode_literals
from django.shortcuts import get_object_or_404, render, redirect
from django.contrib.auth.models import User
from django.http import HttpResponse, HttpResponseRedirect # HttpResponse allows the get_absolute_url to work ## and HttpresponseRedirect redirects page after a process
from .models import *
from .forms import *
from django.contrib import messages
from datetime import datetime, timedelta
def profile_entry(request):
title = 'ADD YOUR PROFILE INFORMATION'
form = ProfileForm(request.POST or None, request.FILES or None)
if form.is_valid():
instance = form.save(commit=False)
date_of_birth = instance.date_of_birth
age_days = (datetime.now().date() - date_of_birth)
age = (age_days/365)
rem_yrs = (60 - int(age))
instance.date_of_retirement = rem_yrs
instance.save()
messages.success(request, 'Successfully Saved')
return redirect('/profile/profile_detail')
context = {
"title": title,
"form": form,
}
return render(request, "profile_entry.html",context)
models.py
[address = models.CharField(max_length=30, blank=True, null=True)
date_of_birth = models.DateTimeField(blank=True, null=True)
email_address = models.CharField(max_length=30, blank=True, null=True)
phone_number = models.CharField(max_length=30, blank=True, null=True)
date_of_hire = models.DateTimeField(blank=True, null=True)
date_of_termination = models.DateField(blank=True, null=True)
date_of_retirement = models.CharField(max_length=30, blank=True, null=True)][1]