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


7
class Currency(MyModel):
Florent Chehab's avatar
Florent Chehab committed
8
9
    code = models.CharField(primary_key=True, max_length=15)
    name = models.CharField(max_length=100)
Florent Chehab's avatar
Florent Chehab committed
10
11
    symbol = models.CharField(null=True, blank=True, max_length=30)
    one_EUR_in_this_currency = models.DecimalField(
Florent Chehab's avatar
Florent Chehab committed
12
13
14
15
16
17
        max_digits=20,
        decimal_places=6,
        validators=[MinValueValidator(0)]
    )


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


24
25
class CurrencyViewSet(MyModelViewSet):
    permission_classes = (permissions.IsAdminUser,)  # TODO : change
Florent Chehab's avatar
Florent Chehab committed
26
27
    queryset = Currency.objects.all()  # pylint: disable=E1101
    serializer_class = CurrencySerializer