city.py 942 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
from backend.models.country import Country
3
from backend.models.my_model import MyModel, MyModelSerializer, MyModelVersionnedViewSet
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 City(MyModel):
Florent Chehab's avatar
Florent Chehab committed
8
    model_config = get_model_config("City")
9

Florent Chehab's avatar
Florent Chehab committed
10 11 12 13 14 15 16 17
    name = models.CharField(max_length=200)
    local_name = models.CharField(max_length=200, null=True, blank=True)
    # We add an area to distinguish similarly named cities
    # in a country
    area = models.CharField(max_length=200, null=True, blank=True)
    country = models.ForeignKey(Country, on_delete=models.PROTECT)


18
class CitySerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
19 20 21 22 23 24

    class Meta:
        model = City
        fields = '__all__'


25
class CityViewSet(MyModelVersionnedViewSet):
26
    permission_classes = get_viewset_permissions("CityViewSet")
Florent Chehab's avatar
Florent Chehab committed
27 28
    queryset = City.objects.all()  # pylint: disable=E1101
    serializer_class = CitySerializer