scholarship.py 1.03 KB
Newer Older
1
2
3
4
5
6
7
8
from django.db import models
from rex.models.module import BasicModule
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator


class Scholarship(BasicModule):

Florent Chehab's avatar
Florent Chehab committed
9
10
    type = models.CharField(max_length=200)  # TODO add required
    currency = models.CharField(max_length=50)  # TODO add required
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    amount_min = models.DecimalField(
        max_digits=20,
        decimal_places=2,
        validators=[MinValueValidator(0)]
    )

    amount_max = models.DecimalField(
        max_digits=20,
        decimal_places=2,
        validators=[MinValueValidator(0)]
    )

    # Need custom validation
    def clean(self, *args, **kwargs):
        if self.amount_max < self.amount_min:
            raise ValidationError(
                "Amount_max should be greater or equal than amount_min")
        super(Scholarship, self).clean(*args, **kwargs)

    def save(self, *args, **kwargs):
        self.full_clean()
        super(Scholarship, self).save(*args, **kwargs)

    class Meta:
        abstract = True