I'm trying to create a new record in my Django model but I just can't. Here is the Sell class model:
class Sell(models.Model):
item = models.OneToOneField(Buy, related_name='sell', on_delete=models.CASCADE)
date = models.DateField(default=timezone.now)
discount = models.DecimalField(max_digits=6, decimal_places=2)
total_paid = models.DecimalField(max_digits=6, decimal_places=2)
buyer = models.ForeignKey(User, related_name='sell', on_delete=models.CASCADE)
Here is the code in my view.py:
Sell.objects.create(item=item,
date=timezone.now,
discount=Decimal(0.00),
total_paid=cart.get_total_price(),
buyer=request.user, )
If I print all of this variables, the result is:
print(item)
266
print(type(item))
<class 'dma.models.Buy'>
print(timezone.now)
<function datetime.date at 0x03D3F460>
print(type(timezone.now))
<class 'function'>
print(type(Decimal(0.00)))
<class 'decimal.Decimal'>
print(cart.get_total_price())
68.00
print(type(cart.get_total_price()))
<class 'decimal.Decimal'>
print(request.user)
Felipe
print(type(request.user))
<class 'django.utils.functional.SimpleLazyObject'>
Error:
Exception Type: TypeError
Exception Value:
expected string or bytes-like object

date=datetime.date, the pasted code doesn't.