diff --git a/apps/account/management/commands/add_account.py b/apps/account/management/commands/add_account.py index fce76f06..7b95d8d1 100644 --- a/apps/account/management/commands/add_account.py +++ b/apps/account/management/commands/add_account.py @@ -15,9 +15,8 @@ class Command(BaseCommand): with connections['legacy'].cursor() as cursor: cursor.execute(''' select a.email, a.id as account_id, a.encrypted_password, a.locale, a.city, - a.confirmed_at as cfd, - case when a.confirmed_at is not null then true else false end as confirmed_at, - case when a.confirmed_at is null then true else false end as unconfirmed_email, + a.confirmed_at as cfd, a.unconfirmed_email, + case when a.confirmed_at is not null then true else false end as confirmed_at, nickname from accounts as a where a.email is not null and a.nickname!='admin' diff --git a/apps/account/migrations/0036_auto_20200205_1457.py b/apps/account/migrations/0036_auto_20200205_1457.py new file mode 100644 index 00000000..94691d14 --- /dev/null +++ b/apps/account/migrations/0036_auto_20200205_1457.py @@ -0,0 +1,34 @@ +# Generated by Django 2.2.7 on 2020-02-05 14:57 + +import django.contrib.postgres.indexes +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0035_userrole_for_team'), + ] + + operations = [ + migrations.AddIndex( + model_name='user', + index=django.contrib.postgres.indexes.GinIndex(fields=['username'], name='account_use_usernam_20b96d_gin'), + ), + migrations.AddIndex( + model_name='user', + index=django.contrib.postgres.indexes.GinIndex(fields=['first_name'], name='account_use_first_n_472c42_gin'), + ), + migrations.AddIndex( + model_name='user', + index=django.contrib.postgres.indexes.GinIndex(fields=['last_name'], name='account_use_last_na_595e99_gin'), + ), + migrations.AddIndex( + model_name='user', + index=django.contrib.postgres.indexes.GinIndex(fields=['email'], name='account_use_email_2f1668_gin'), + ), + migrations.AddIndex( + model_name='user', + index=django.contrib.postgres.indexes.GinIndex(fields=['phone'], name='account_use_phone_9593fb_gin'), + ), + ] diff --git a/apps/account/models.py b/apps/account/models.py index 76513e5e..bc6ca299 100644 --- a/apps/account/models.py +++ b/apps/account/models.py @@ -5,6 +5,7 @@ from typing import List from django.conf import settings from django.contrib.auth.models import AbstractUser, UserManager as BaseUserManager +from django.contrib.postgres.indexes import GinIndex from django.contrib.postgres.search import TrigramSimilarity from django.core.mail import send_mail from django.db import models @@ -289,6 +290,13 @@ class User(PhoneModelMixin, AbstractUser): """Meta class.""" verbose_name = _('User') verbose_name_plural = _('Users') + indexes = [ + GinIndex(fields=['username']), + GinIndex(fields=['first_name']), + GinIndex(fields=['last_name']), + GinIndex(fields=['email']), + GinIndex(fields=['phone']), + ] def __str__(self): """String method.""" diff --git a/apps/establishment/serializers/back.py b/apps/establishment/serializers/back.py index 9b1d0c81..bf17b6ab 100644 --- a/apps/establishment/serializers/back.py +++ b/apps/establishment/serializers/back.py @@ -14,7 +14,7 @@ from establishment import models, serializers as model_serializers from establishment.models import ContactEmail, ContactPhone, EstablishmentEmployee from establishment.serializers.common import ContactPhonesSerializer from gallery.models import Image -from location.serializers import AddressDetailSerializer, TranslatedField +from location.serializers import AddressDetailSerializer, TranslatedField, AddressBaseSerializer from main.models import Currency from main.serializers import AwardSerializer from utils.decorators import with_base_attributes @@ -58,6 +58,7 @@ class EstablishmentListCreateSerializer(model_serializers.EstablishmentBaseSeria queryset=models.Address.objects.all(), write_only=True ) + address = AddressBaseSerializer(read_only=True, allow_null=True) transliterated_name = serializers.CharField( required=False, allow_null=True, allow_blank=True ) @@ -98,6 +99,8 @@ class EstablishmentListCreateSerializer(model_serializers.EstablishmentBaseSeria 'website', 'phones', 'contact_phones', + 'toque_number', + 'public_mark', 'emails', 'price_level', 'toque_number', @@ -116,6 +119,7 @@ class EstablishmentListCreateSerializer(model_serializers.EstablishmentBaseSeria 'lastable_id', 'tags', 'tz', + 'address', 'address_id', 'status', 'status_display', diff --git a/apps/news/models.py b/apps/news/models.py index a792fc18..e840f9c5 100644 --- a/apps/news/models.py +++ b/apps/news/models.py @@ -19,7 +19,8 @@ from rest_framework.reverse import reverse from main.models import Carousel from rating.models import Rating from utils.models import ( - BaseAttributes, FavoritesMixin, GalleryMixin, HasTagsMixin, IntermediateGalleryModelMixin, ProjectBaseMixin, + BaseAttributes, FavoritesMixin, GalleryMixin, HasTagsMixin, IntermediateGalleryModelMixin, + ProjectBaseMixin, TJSONField, TranslatedFieldsMixin, TypeDefaultImageMixin, ) from utils.querysets import TranslationQuerysetMixin @@ -252,7 +253,7 @@ class NewsQuerySet(TranslationQuerysetMixin): ).filter(relevance__gte=0.3).order_by('-relevance') def available_news(self, user, country_code: str): - """Return QuerySet with news that user has an access.""" + """Return QuerySet with news that user has access.""" return self.filter(site__country__code=country_code) if not user.is_superuser else self diff --git a/apps/report/models.py b/apps/report/models.py index ef3d197e..b89e992d 100644 --- a/apps/report/models.py +++ b/apps/report/models.py @@ -68,6 +68,10 @@ class Report(ProjectBaseMixin): verbose_name = _('Report') verbose_name_plural = _('Reports') + def __str__(self): + """Implement `str` dunder method.""" + return f'{self.id}: {self.get_category_display()} ({self.url})' + def get_body_email_message(self): """Prepare the body of the email message""" return {