1
Typeerror with calculated field
unsupported operand type(s) for *: 'int' and 'NoneType'
error in Return line below
py.models
def get_subtotal(self):
return self.price_sale * self.quantity
subtotal = property(get_subtotal)
admin py.
class SaleDetailInline(admin.TabularInline):
list_display = ['product', 'quantity', 'price_sale', 'subtotal']
readonly_fields = ['subtotal', ]
model = SaleDetail
extra = 0
In the view the subtotal works, but in Admin does not.
So what do you suggest: (price_sale * Quantity) or 0 ?
– Regis Santos
@Regisdasilva edited the answer and added the solutions
– Paulo
A simple way is to use the
or
:return self.price_sale * (self.quantify or 0)
– drgarcia1986
@drgarcia1986 se
self.price_sale
be equalNone
error will occur, the right is to check both variables and not only theself.quantity
.– Paulo
You’re right, I can’t consider the camp
self.price_sale
has value.– drgarcia1986