Commit 64384ff6 authored by Florent Chehab's avatar Florent Chehab
Browse files

Class hierarchy cleaned

parent abe28293
# Generated by Django 2.0.3 on 2018-08-30 14:23
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='countrytaggeditem',
name='country',
field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='country_items', serialize=False, to='backend.Country'),
),
]
from django.db import models from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.models.location import City from backend.models.location import City
from backend.models.tag import Tag
class CityTaggedItem(BasicModule): class CityTaggedItem(TaggedItem):
city = models.OneToOneField( city = models.OneToOneField(
City, on_delete=models.PROTECT, related_name='city_items', primary_key=True) City, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)
@classmethod @classmethod
def get_serializer(cls): def get_serializer(cls):
...@@ -17,13 +15,13 @@ class CityTaggedItem(BasicModule): ...@@ -17,13 +15,13 @@ class CityTaggedItem(BasicModule):
unique_together = ('city', 'tag') unique_together = ('city', 'tag')
class CityTaggedItemSerializer(BasicModuleSerializer): class CityTaggedItemSerializer(TaggedItemSerializer):
class Meta: class Meta:
model = CityTaggedItem model = CityTaggedItem
fields = '__all__' fields = '__all__'
class CityTaggedItemViewSet(BasicModuleViewSet): class CityTaggedItemViewSet(TaggedItemViewSet):
queryset = CityTaggedItem.objects.all() # pylint: disable=E1101 queryset = CityTaggedItem.objects.all() # pylint: disable=E1101
serializer_class = CityTaggedItemSerializer serializer_class = CityTaggedItemSerializer
from django.db import models from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.models.location import Country from backend.models.location import Country
from backend.models.tag import Tag
class CountryTaggedItem(BasicModule): class CountryTaggedItem(TaggedItem):
country = models.OneToOneField( country = models.OneToOneField(
Country, on_delete=models.PROTECT, related_name='city_items', primary_key=True) Country, on_delete=models.PROTECT, related_name='country_items', primary_key=True)
tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)
@classmethod @classmethod
def get_serializer(cls): def get_serializer(cls):
...@@ -17,13 +15,13 @@ class CountryTaggedItem(BasicModule): ...@@ -17,13 +15,13 @@ class CountryTaggedItem(BasicModule):
unique_together = ('country', 'tag') unique_together = ('country', 'tag')
class CountryTaggedItemSerializer(BasicModuleSerializer): class CountryTaggedItemSerializer(TaggedItemSerializer):
class Meta: class Meta:
model = CountryTaggedItem model = CountryTaggedItem
fields = '__all__' fields = '__all__'
class CountryTaggedItemViewSet(BasicModuleViewSet): class CountryTaggedItemViewSet(TaggedItemViewSet):
queryset = CountryTaggedItem.objects.all() # pylint: disable=E1101 queryset = CountryTaggedItem.objects.all() # pylint: disable=E1101
serializer_class = CountryTaggedItemSerializer serializer_class = CountryTaggedItemSerializer
from .tag import Tag, TagSerializer, TagViewSet # noqa: F401 from .tag import Tag, TagSerializer, TagViewSet # noqa: F401
from .taggedItem import TaggedItem, TaggedItemSerializer, TaggedItemViewSet # noqa: F401
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from .tag import Tag
class TaggedItem(BasicModule):
tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)
class Meta:
abstract = True
class TaggedItemSerializer(BasicModuleSerializer):
pass
class TaggedItemViewSet(BasicModuleViewSet):
pass
from django.db import models from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import Campus from backend.models.university import Campus
from backend.models.tag import Tag from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
class CampusTaggedItem(BasicModule): class CampusTaggedItem(TaggedItem):
campus = models.OneToOneField( campus = models.OneToOneField(
Campus, on_delete=models.PROTECT, related_name='city_items', primary_key=True) Campus, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)
@classmethod @classmethod
def get_serializer(cls): def get_serializer(cls):
...@@ -17,13 +15,13 @@ class CampusTaggedItem(BasicModule): ...@@ -17,13 +15,13 @@ class CampusTaggedItem(BasicModule):
unique_together = ('campus', 'tag') unique_together = ('campus', 'tag')
class CampusTaggedItemSerializer(BasicModuleSerializer): class CampusTaggedItemSerializer(TaggedItemSerializer):
class Meta: class Meta:
model = CampusTaggedItem model = CampusTaggedItem
fields = '__all__' fields = '__all__'
class CampusTaggedItemViewSet(BasicModuleViewSet): class CampusTaggedItemViewSet(TaggedItemViewSet):
queryset = CampusTaggedItem.objects.all() # pylint: disable=E1101 queryset = CampusTaggedItem.objects.all() # pylint: disable=E1101
serializer_class = CampusTaggedItemSerializer serializer_class = CampusTaggedItemSerializer
from django.db import models from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend.models.university import University from backend.models.university import University
from backend.models.tag import Tag
class UniversityTaggedItem(BasicModule): class UniversityTaggedItem(TaggedItem):
university = models.OneToOneField( university = models.OneToOneField(
University, on_delete=models.PROTECT, related_name='city_items', primary_key=True) University, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)
@classmethod @classmethod
def get_serializer(cls): def get_serializer(cls):
...@@ -17,13 +15,13 @@ class UniversityTaggedItem(BasicModule): ...@@ -17,13 +15,13 @@ class UniversityTaggedItem(BasicModule):
unique_together = ('university', 'tag') unique_together = ('university', 'tag')
class UniversityTaggedItemSerializer(BasicModuleSerializer): class UniversityTaggedItemSerializer(TaggedItemSerializer):
class Meta: class Meta:
model = UniversityTaggedItem model = UniversityTaggedItem
fields = '__all__' fields = '__all__'
class UniversityTaggedItemViewSet(BasicModuleViewSet): class UniversityTaggedItemViewSet(TaggedItemViewSet):
queryset = UniversityTaggedItem.objects.all() # pylint: disable=E1101 queryset = UniversityTaggedItem.objects.all() # pylint: disable=E1101
serializer_class = UniversityTaggedItemSerializer serializer_class = UniversityTaggedItemSerializer
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