i have problem with validating Django Form because i can't save model before cleaning of course. I have reservation model:
class Reservation(models.Model):
from = models.DateTimeField()
to = models.DateTimeField()
total_price = models.DecimalField()
paid = models.DecimalField()
def calculate_price(self):
self.total_price = some_magic(self.from, self.to)
and form:
class ReservationForm(forms.ModelForm):
payment_amount = forms.DecimalField()
class Meta:
model = Reservation
def clean(self):
????
I want to verify in clean method if payment_amount is not greater than total_price but total_price is not updated - i call calculate_price() after saving model.
Can i raise ValidationError in view after price calculation?