currency.py 927 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.core.validators import MinValueValidator
2 3
from django.db import models

4 5 6 7
from backend_app.models.abstract.base import (
    BaseModel,
    BaseModelSerializer,
    BaseModelViewSet,
8
)
9
from backend_app.permissions.app_permissions import ReadOnly
Florent Chehab's avatar
Florent Chehab committed
10 11


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


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


27
class CurrencyViewSet(BaseModelViewSet):
Florent Chehab's avatar
Florent Chehab committed
28 29
    queryset = Currency.objects.all()  # pylint: disable=E1101
    serializer_class = CurrencySerializer
30 31
    permission_classes = (ReadOnly,)
    end_point_route = "currencies"