refactored a little, added Gin indexes to account.User model.
This commit is contained in:
parent
285f52ce30
commit
061c96d198
34
apps/account/migrations/0036_auto_20200205_1457.py
Normal file
34
apps/account/migrations/0036_auto_20200205_1457.py
Normal file
|
|
@ -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'),
|
||||
),
|
||||
]
|
||||
|
|
@ -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."""
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user