Added field - vintage_year, absolute image_url to Carousel ListAPIView
This commit is contained in:
parent
af0c134957
commit
6e7a617a67
|
|
@ -7,6 +7,7 @@ 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 review.models import Review
|
||||||
from utils.models import (ProjectBaseMixin, TJSONField,
|
from utils.models import (ProjectBaseMixin, TJSONField,
|
||||||
TranslatedFieldsMixin, ImageMixin)
|
TranslatedFieldsMixin, ImageMixin)
|
||||||
from utils.querysets import ContentTypeQuerySetMixin
|
from utils.querysets import ContentTypeQuerySetMixin
|
||||||
|
|
@ -311,6 +312,13 @@ class Carousel(models.Model):
|
||||||
if hasattr(self.content_object, 'awards'):
|
if hasattr(self.content_object, 'awards'):
|
||||||
return self.content_object.awards
|
return self.content_object.awards
|
||||||
|
|
||||||
|
@property
|
||||||
|
def vintage_year(self):
|
||||||
|
if hasattr(self.content_object, 'reviews'):
|
||||||
|
review_qs = self.content_object.reviews.by_status(Review.READY)
|
||||||
|
if review_qs.exists():
|
||||||
|
return review_qs.last().vintage
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def toque_number(self):
|
def toque_number(self):
|
||||||
if hasattr(self.content_object, 'toque_number'):
|
if hasattr(self.content_object, 'toque_number'):
|
||||||
|
|
@ -326,8 +334,8 @@ class Carousel(models.Model):
|
||||||
# Check if Generic obj has an image
|
# Check if Generic obj has an image
|
||||||
if not hasattr(self.content_object.image, 'url'):
|
if not hasattr(self.content_object.image, 'url'):
|
||||||
# Check if Generic obj has a FK to gallery
|
# Check if Generic obj has a FK to gallery
|
||||||
return self.content_object.image.image.url
|
return self.content_object.image.image
|
||||||
return self.content_object.image.url
|
return self.content_object.image
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def model_name(self):
|
def model_name(self):
|
||||||
|
|
|
||||||
|
|
@ -134,8 +134,9 @@ class CarouselListSerializer(serializers.ModelSerializer):
|
||||||
name = serializers.CharField()
|
name = serializers.CharField()
|
||||||
toque_number = serializers.CharField()
|
toque_number = serializers.CharField()
|
||||||
public_mark = serializers.CharField()
|
public_mark = serializers.CharField()
|
||||||
image = serializers.URLField()
|
image = serializers.ImageField()
|
||||||
awards = AwardBaseSerializer(many=True)
|
awards = AwardBaseSerializer(many=True)
|
||||||
|
vintage_year = serializers.IntegerField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -148,4 +149,5 @@ class CarouselListSerializer(serializers.ModelSerializer):
|
||||||
'toque_number',
|
'toque_number',
|
||||||
'public_mark',
|
'public_mark',
|
||||||
'image',
|
'image',
|
||||||
|
'vintage_year',
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user