city.py 937 Bytes
Newer Older
1
from django.db import models
2 3 4 5 6

from backend_app.models.abstract.base import (
    BaseModel,
    BaseModelSerializer,
    BaseModelViewSet,
7
)
8
from backend_app.models.country import Country
9
from backend_app.permissions.app_permissions import ReadOnly, IsStaff
10 11


12
class City(BaseModel):
13
    name = models.CharField(max_length=200)
14
    local_name = models.CharField(max_length=200, default="", blank=True)
15 16
    # We add an area to distinguish similarly named cities
    # in a country
17
    area = models.CharField(max_length=200, default="", blank=True)
18 19 20
    country = models.ForeignKey(Country, on_delete=models.PROTECT)


21
class CitySerializer(BaseModelSerializer):
22 23
    class Meta:
        model = City
24
        fields = "__all__"
25 26


27
class CityViewSet(BaseModelViewSet):
28 29
    queryset = City.objects.all()  # pylint: disable=E1101
    serializer_class = CitySerializer
30 31
    permission_classes = (IsStaff | ReadOnly,)
    end_point_route = "cities"