GM-25: Получение главной зоны
This commit is contained in:
parent
10d9b52bec
commit
555aa9a4e1
|
|
@ -46,3 +46,6 @@ class CurrencContentAdmin(admin.ModelAdmin):
|
||||||
"""CurrencContent admin"""
|
"""CurrencContent admin"""
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.Carousel)
|
||||||
|
class CarouselAdmin(admin.ModelAdmin):
|
||||||
|
"""Carousel admin."""
|
||||||
|
|
|
||||||
27
apps/main/migrations/0014_carousel.py
Normal file
27
apps/main/migrations/0014_carousel.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-09-13 11:33
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('contenttypes', '0002_remove_content_type_name'),
|
||||||
|
('main', '0013_auto_20190901_1032'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Carousel',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('object_id', models.PositiveIntegerField()),
|
||||||
|
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Carousel',
|
||||||
|
'verbose_name_plural': 'Carousel',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -7,7 +7,9 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from location.models import Country
|
from location.models import Country
|
||||||
from main import methods
|
from main import methods
|
||||||
from utils.models import ProjectBaseMixin, TJSONField, TranslatedFieldsMixin
|
from utils.models import (ProjectBaseMixin, TJSONField,
|
||||||
|
TranslatedFieldsMixin, ImageMixin)
|
||||||
|
from utils.querysets import ContentTypeQuerySetMixin
|
||||||
from configuration.models import TranslationSettings
|
from configuration.models import TranslationSettings
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -253,6 +255,10 @@ class MetaData(TranslatedFieldsMixin, models.Model):
|
||||||
return f'id:{self.id}-{label}'
|
return f'id:{self.id}-{label}'
|
||||||
|
|
||||||
|
|
||||||
|
class MetaDataContentQuerySet(ContentTypeQuerySetMixin):
|
||||||
|
"""QuerySets for MetaDataContent model."""
|
||||||
|
|
||||||
|
|
||||||
class MetaDataContent(models.Model):
|
class MetaDataContent(models.Model):
|
||||||
"""MetaDataContent model."""
|
"""MetaDataContent model."""
|
||||||
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||||
|
|
@ -260,6 +266,8 @@ class MetaDataContent(models.Model):
|
||||||
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||||
metadata = models.ForeignKey(MetaData, on_delete=models.CASCADE)
|
metadata = models.ForeignKey(MetaData, on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
objects = MetaDataContentQuerySet.as_manager()
|
||||||
|
|
||||||
|
|
||||||
class Currency(models.Model):
|
class Currency(models.Model):
|
||||||
"""Currency model."""
|
"""Currency model."""
|
||||||
|
|
@ -271,3 +279,53 @@ class Currency(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.name}'
|
return f'{self.name}'
|
||||||
|
|
||||||
|
|
||||||
|
class CarouselQuerySet(models.QuerySet):
|
||||||
|
"""Carousel QuerySet."""
|
||||||
|
|
||||||
|
|
||||||
|
class Carousel(models.Model):
|
||||||
|
"""Carousel model."""
|
||||||
|
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||||
|
object_id = models.PositiveIntegerField()
|
||||||
|
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||||
|
|
||||||
|
objects = CarouselQuerySet.as_manager()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
verbose_name = _('Carousel')
|
||||||
|
verbose_name_plural = _('Carousel')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
if hasattr(self.content_object, 'name'):
|
||||||
|
return self.content_object.name
|
||||||
|
if hasattr(self.content_object, 'title'):
|
||||||
|
return self.content_object.title_translated
|
||||||
|
|
||||||
|
@property
|
||||||
|
def awards(self):
|
||||||
|
if hasattr(self.content_object, 'awards'):
|
||||||
|
return self.content_object.awards
|
||||||
|
|
||||||
|
@property
|
||||||
|
def toque_number(self):
|
||||||
|
if hasattr(self.content_object, 'toque_number'):
|
||||||
|
return self.content_object.toque_number
|
||||||
|
|
||||||
|
@property
|
||||||
|
def public_mark(self):
|
||||||
|
if hasattr(self.content_object, 'public_mark'):
|
||||||
|
return self.content_object.public_mark
|
||||||
|
|
||||||
|
@property
|
||||||
|
def image(self):
|
||||||
|
if not hasattr(self.content_object.image, 'url'):
|
||||||
|
return self.content_object.image.image.url
|
||||||
|
return self.content_object.image.url
|
||||||
|
|
||||||
|
@property
|
||||||
|
def model_name(self):
|
||||||
|
return self.content_object.__class__.__name__
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
"""Main app serializers."""
|
"""Main app serializers."""
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from location.serializers import CountrySerializer
|
from location.serializers import CountrySerializer
|
||||||
from main import models
|
from main import models
|
||||||
|
|
||||||
|
|
@ -82,8 +83,8 @@ class SiteSerializer(serializers.ModelSerializer):
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
|
||||||
class AwardSerializer(serializers.ModelSerializer):
|
class AwardBaseSerializer(serializers.ModelSerializer):
|
||||||
"""Award serializer."""
|
"""Award base serializer."""
|
||||||
|
|
||||||
title_translated = serializers.CharField(read_only=True, allow_null=True)
|
title_translated = serializers.CharField(read_only=True, allow_null=True)
|
||||||
|
|
||||||
|
|
@ -92,11 +93,18 @@ class AwardSerializer(serializers.ModelSerializer):
|
||||||
fields = [
|
fields = [
|
||||||
'id',
|
'id',
|
||||||
'title_translated',
|
'title_translated',
|
||||||
'award_type',
|
|
||||||
'vintage_year',
|
'vintage_year',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class AwardSerializer(AwardBaseSerializer):
|
||||||
|
"""Award serializer."""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = models.Award
|
||||||
|
fields = AwardBaseSerializer.Meta.fields + ['award_type', ]
|
||||||
|
|
||||||
|
|
||||||
class MetaDataContentSerializer(serializers.ModelSerializer):
|
class MetaDataContentSerializer(serializers.ModelSerializer):
|
||||||
id = serializers.IntegerField(source='metadata.id', read_only=True,)
|
id = serializers.IntegerField(source='metadata.id', read_only=True,)
|
||||||
label_translated = serializers.CharField(
|
label_translated = serializers.CharField(
|
||||||
|
|
@ -117,4 +125,27 @@ class CurrencySerializer(serializers.ModelSerializer):
|
||||||
fields = [
|
fields = [
|
||||||
'id',
|
'id',
|
||||||
'name'
|
'name'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CarouselListSerializer(serializers.ModelSerializer):
|
||||||
|
"""Serializer for retrieving list of carousel items."""
|
||||||
|
model_name = serializers.CharField()
|
||||||
|
name = serializers.CharField()
|
||||||
|
toque_number = serializers.CharField()
|
||||||
|
public_mark = serializers.CharField()
|
||||||
|
image = serializers.URLField()
|
||||||
|
awards = AwardBaseSerializer(many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
model = models.Carousel
|
||||||
|
fields = [
|
||||||
|
'id',
|
||||||
|
'model_name',
|
||||||
|
'name',
|
||||||
|
'awards',
|
||||||
|
'toque_number',
|
||||||
|
'public_mark',
|
||||||
|
'image',
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,5 @@ urlpatterns = [
|
||||||
path('site-settings/<subdomain>/', views.SiteSettingsView.as_view(), name='site-settings'),
|
path('site-settings/<subdomain>/', views.SiteSettingsView.as_view(), name='site-settings'),
|
||||||
path('awards/', views.AwardView.as_view(), name='awards_list'),
|
path('awards/', views.AwardView.as_view(), name='awards_list'),
|
||||||
path('awards/<int:pk>/', views.AwardRetrieveView.as_view(), name='awards_retrieve'),
|
path('awards/<int:pk>/', views.AwardRetrieveView.as_view(), name='awards_retrieve'),
|
||||||
|
path('carousel/', views.CarouselListView.as_view(), name='carousel-list'),
|
||||||
]
|
]
|
||||||
|
|
@ -84,3 +84,11 @@ class AwardRetrieveView(generics.RetrieveAPIView):
|
||||||
serializer_class = serializers.AwardSerializer
|
serializer_class = serializers.AwardSerializer
|
||||||
queryset = models.Award.objects.all()
|
queryset = models.Award.objects.all()
|
||||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
|
||||||
|
class CarouselListView(generics.ListAPIView):
|
||||||
|
"""Return list of carousel items."""
|
||||||
|
queryset = models.Carousel.objects.all()
|
||||||
|
serializer_class = serializers.CarouselListSerializer
|
||||||
|
permission_classes = (permissions.AllowAny, )
|
||||||
|
pagination_class = None
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,6 @@ def generate_string_code(size=64,
|
||||||
|
|
||||||
def get_contenttype(app_label: str, model: str):
|
def get_contenttype(app_label: str, model: str):
|
||||||
"""Get ContentType instance by app_label and model"""
|
"""Get ContentType instance by app_label and model"""
|
||||||
if app_label and model:
|
qs = ContentType.objects.filter(app_label=app_label, model=model)
|
||||||
qs = ContentType.objects.filter(app_label=app_label, model=model)
|
if qs.exists():
|
||||||
if qs.exists():
|
return qs.first()
|
||||||
return qs.first()
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user