Visible tags for establishments
This commit is contained in:
parent
303d7f5277
commit
9212f85ee5
|
|
@ -20,6 +20,7 @@ from timezone_field import TimeZoneField
|
|||
from collection.models import Collection
|
||||
from location.models import Address
|
||||
from main.models import Award, Currency
|
||||
from tag.models import TagCategory
|
||||
from review.models import Review
|
||||
from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin,
|
||||
TranslatedFieldsMixin, BaseAttributes, GalleryModelMixin,
|
||||
|
|
@ -407,6 +408,12 @@ class Establishment(GalleryModelMixin, ProjectBaseMixin, URLImageMixin, Translat
|
|||
def __str__(self):
|
||||
return f'id:{self.id}-{self.name}'
|
||||
|
||||
@property
|
||||
def visible_tags(self):
|
||||
return self.tags.exclude(category__value_type=TagCategory.BOOLEAN)\
|
||||
.exclude(category__index_name__in=['guide', 'collection', 'purchased_item',
|
||||
'business_tag', 'business_tags_de'])
|
||||
|
||||
# todo: recalculate toque_number
|
||||
def recalculate_toque_number(self):
|
||||
toque_number = 0
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ class EstablishmentBaseSerializer(ProjectModelSerializer):
|
|||
|
||||
address = AddressBaseSerializer()
|
||||
in_favorites = serializers.BooleanField(allow_null=True)
|
||||
tags = TagBaseSerializer(read_only=True, many=True)
|
||||
tags = TagBaseSerializer(read_only=True, many=True, source='visible_tags')
|
||||
currency = CurrencySerializer()
|
||||
type = EstablishmentTypeBaseSerializer(source='establishment_type', read_only=True)
|
||||
subtypes = EstablishmentSubTypeBaseSerializer(many=True, source='establishment_subtypes')
|
||||
|
|
|
|||
|
|
@ -48,6 +48,13 @@ class EstablishmentDocument(Document):
|
|||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
},
|
||||
multi=True)
|
||||
visible_tags = fields.ObjectField(
|
||||
properties={
|
||||
'id': fields.IntegerField(attr='id'),
|
||||
'label': fields.ObjectField(attr='label_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
},
|
||||
multi=True)
|
||||
schedule = fields.ListField(fields.ObjectField(
|
||||
properties={
|
||||
'id': fields.IntegerField(attr='id'),
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ class EstablishmentDocumentSerializer(DocumentSerializer):
|
|||
establishment_type = EstablishmentTypeSerializer()
|
||||
establishment_subtypes = EstablishmentTypeSerializer(many=True)
|
||||
address = AddressDocumentSerializer(allow_null=True)
|
||||
tags = TagsDocumentSerializer(many=True)
|
||||
tags = TagsDocumentSerializer(many=True, source='visible_tags')
|
||||
schedule = ScheduleDocumentSerializer(many=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
23
apps/tag/migrations/0015_auto_20191118_1210.py
Normal file
23
apps/tag/migrations/0015_auto_20191118_1210.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 2.2.7 on 2019-11-18 12:10
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tag', '0014_tag_old_id_meta_product'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='tag',
|
||||
name='value',
|
||||
field=models.CharField(blank=True, db_index=True, default=None, max_length=255, null=True, verbose_name='indexing name'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='tagcategory',
|
||||
name='value_type',
|
||||
field=models.CharField(choices=[('string', 'string'), ('list', 'list'), ('integer', 'integer'), ('float', 'float'), ('percentage', 'percentage'), ('bool', 'boolean')], default='list', max_length=255, verbose_name='value type'),
|
||||
),
|
||||
]
|
||||
|
|
@ -35,7 +35,7 @@ class Tag(TranslatedFieldsMixin, models.Model):
|
|||
label = TJSONField(blank=True, null=True, default=None,
|
||||
verbose_name=_('label'),
|
||||
help_text='{"en-GB":"some text"}')
|
||||
value = models.CharField(_('indexing name'), max_length=255, blank=True,
|
||||
value = models.CharField(_('indexing name'), max_length=255, blank=True, db_index=True,
|
||||
null=True, default=None)
|
||||
category = models.ForeignKey('TagCategory', on_delete=models.CASCADE,
|
||||
null=True, related_name='tags',
|
||||
|
|
@ -124,6 +124,7 @@ class TagCategory(TranslatedFieldsMixin, models.Model):
|
|||
INTEGER = 'integer'
|
||||
FLOAT = 'float'
|
||||
PERCENTAGE = 'percentage'
|
||||
BOOLEAN = 'bool'
|
||||
|
||||
VALUE_TYPE_CHOICES = (
|
||||
(STRING, _('string')),
|
||||
|
|
@ -131,6 +132,7 @@ class TagCategory(TranslatedFieldsMixin, models.Model):
|
|||
(INTEGER, _('integer')),
|
||||
(FLOAT, _('float')),
|
||||
(PERCENTAGE, _('percentage')),
|
||||
(BOOLEAN, _('boolean')),
|
||||
)
|
||||
|
||||
label = TJSONField(blank=True, null=True, default=None,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user