currency.py 794 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1 2
from django.db import models
from django.core.validators import MinValueValidator
3 4 5 6
from backend_app.models.abstract.base import (
    BaseModel,
    BaseModelSerializer,
    BaseModelViewSet,
7
)
Florent Chehab's avatar
Florent Chehab committed
8 9


10
class Currency(BaseModel):
11

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


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


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