I am creating a task in Django where I need to take all the orders and check the creation date to see how much time has elapsed, in case 2 days have passed to execute a code and in case 4 have passed, execute a different one.
Right now my model is like this:
class Pedido(models.Model):
id = models.CharField(primary_key=True, max_length=9, editable=False)
fecha = models.DateTimeField(auto_now_add = True)
precio_producto = models.DecimalField(max_digits=12,decimal_places=2)
precio_envio = models.DecimalField(max_digits=6,decimal_places=2)
nom_producto = models.CharField(max_length = 40)
talla = models.CharField(max_length = 5)
marca = models.CharField(max_length = 20)
the code that I have right now is like this:
pedidos = Pedido.objects.all()
for p in pedidos:
tiempo_transcurrido = date.today() - p.fecha
if tiempo_transcurrido == timedelta(days=2):
pass
elif tiempo_transcurrido == timedelta(days=4):
pass
elif tiempo_transcurrido == timedelta(days=5):
pass
The server returns this error:
days = date.today () - p.f_ped TypeError: unsupported operand type (s) for -: 'datetime.date' and 'datetime.datetime'