Commit 3a2008a5 authored by Florent Chehab's avatar Florent Chehab

location files separated

parent a0dc489b
......@@ -43,7 +43,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'general.middleware.LoginRequiredMiddleware',
# 'general.middleware.LoginRequiredMiddleware',
]
LOGIN_URL = '/user/login'
......
# Generated by Django 2.0.3 on 2018-08-21 12:22
from django.db import migrations, models
import rex.utils.friendly_path
class Migration(migrations.Migration):
dependencies = [
('rex', '0018_auto_20180821_1127'),
]
operations = [
migrations.AlterField(
model_name='universityphoto',
name='photo',
field=models.ImageField(default='path/to/my/default/image.jpg', max_length=250, upload_to=rex.utils.friendly_path.friendly_path('uploads/universities/photos/', 'title')),
),
]
from .location import location # noqa: F401
from .university import university # noqa: F401
from .module import VersionnedModule # noqa: F401
from .location import Country, CountrySerializer, CountryViewSet # noqa: F401
from .location import City, CitySerializer, CityViewSet # noqa: F401
from .country import Country, CountrySerializer, CountryViewSet # noqa: F401
from .city import City, CitySerializer, CityViewSet # noqa: F401
from django.db import models
from rest_framework import serializers, permissions
from rex.models.tools import DictModeViewSet
from rex.models.location import Country
# Data model based on : https://unstats.un.org/unsd/methodology/m49/overview/
class City(models.Model):
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)
"""
API RELATED STUFF BELLOW
"""
class CitySerializer(serializers.ModelSerializer):
country_url = serializers.SerializerMethodField()
def get_country_url(self, obj):
return serializers.HyperlinkedRelatedField(
view_name='country-detail',
read_only=True) \
.get_url(obj.country, view_name='country-detail',
request=self.context['request'], format=None)
class Meta:
model = City
fields = '__all__'
class CityViewSet(DictModeViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
queryset = City.objects.all() # pylint: disable=E1101
serializer_class = CitySerializer
......@@ -20,15 +20,6 @@ class Country(models.Model):
max_length=3, null=True, blank=True)
class City(models.Model):
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)
"""
API RELATED STUFF BELLOW
"""
......@@ -38,34 +29,10 @@ class CountrySerializer(serializers.ModelSerializer):
class Meta:
model = Country
fields = ('name', 'iso_alpha2_code', 'iso_alpha3_code',
'region_name', 'region_un_code',
'sub_region_name', 'sub_region_un_code',
'intermediate_region_name', 'intermediate_region_un_code')
fields = '__all__'
class CountryViewSet(DictModeViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
queryset = Country.objects.all() # pylint: disable=E1101
serializer_class = CountrySerializer
class CitySerializer(serializers.ModelSerializer):
country_url = serializers.SerializerMethodField()
def get_country_url(self, obj):
return serializers.HyperlinkedRelatedField(
view_name='country-detail',
read_only=True) \
.get_url(obj.country, view_name='country-detail',
request=self.context['request'], format=None)
class Meta:
model = City
fields = ('name', 'local_name', 'area', 'country', 'country_url', 'id')
class CityViewSet(DictModeViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
queryset = City.objects.all() # pylint: disable=E1101
serializer_class = CitySerializer
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment