These are chat archives for django/django

8th
Jun 2018
Manish Thakur
@manishth
Jun 08 2018 11:17

Hello Everyone, I am trying to learn Django and I am stuck with one issue:
I have two models with a decimal field

total = models.DecimalField(default=0.00, max_digits=5, decimal_places=2)

&

price = models.DecimalField(decimal_places=2, max_digits=5, default=1.00)

I am trying to add these two values in my view function

my_total = cart_obj.total+product_obj.price

but I am getting this error

Type Error unsupported operand type(s) for +: 'float' and 'decimal.Decimal'
:]
@elcolie
Jun 08 2018 11:27
@manishth Put import pdb; pdb.set_trace() to the line
At least you have to cast Decial to float first before proceed addition
Manish Thakur
@manishth
Jun 08 2018 12:11
@elcolie thanks :) but shouldn't they be of the same type as both are declared a DecimalField in the model?
kashyap_py_dev
@Neerajkashyap
Jun 08 2018 13:15
Hi everyone. I am looking for a drag and drop editors, like Elementor in Wordpress. Is there any elementor type page builder in Django ?
Lefort
@PabloLefort
Jun 08 2018 14:59
@Neerajkashyap you'r using some django based cms?
:]
@elcolie
Jun 08 2018 15:35
@manishth I have no idea. Since I work with money I use django-money