currency.py 965 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1 2
from django.db import models
from django.core.validators import MinValueValidator
3
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
Florent Chehab's avatar
Florent Chehab committed
4
from backend.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
5 6


7
class Currency(MyModel):
Florent Chehab's avatar
Florent Chehab committed
8
    model_config = get_model_config("Currency")
9

Florent Chehab's avatar
Florent Chehab committed
10
    code = models.CharField(primary_key=True, max_length=3)
Florent Chehab's avatar
Florent Chehab committed
11
    name = models.CharField(max_length=100)
12
    symbol = models.CharField(default='', blank=True, max_length=30)
Florent Chehab's avatar
Florent Chehab committed
13
    one_EUR_in_this_currency = models.DecimalField(
Florent Chehab's avatar
Florent Chehab committed
14 15 16 17 18 19
        max_digits=20,
        decimal_places=6,
        validators=[MinValueValidator(0)]
    )


20
class CurrencySerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
21 22
    class Meta:
        model = Currency
Florent Chehab's avatar
Florent Chehab committed
23
        fields = '__all__'
Florent Chehab's avatar
Florent Chehab committed
24 25


26
class CurrencyViewSet(MyModelViewSet):
27
    permission_classes = get_viewset_permissions("CurrencyViewSet")
Florent Chehab's avatar
Florent Chehab committed
28 29
    queryset = Currency.objects.all()  # pylint: disable=E1101
    serializer_class = CurrencySerializer