recalculate toque_number for other countries
This commit is contained in:
parent
47b7a7bde1
commit
972e456f20
19
apps/establishment/migrations/0049_auto_20191031_1616.py
Normal file
19
apps/establishment/migrations/0049_auto_20191031_1616.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 2.2.4 on 2019-10-31 16:16
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('establishment', '0048_ratingstrategy'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='ratingstrategy',
|
||||
name='country',
|
||||
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='location.Country', verbose_name='Country'),
|
||||
),
|
||||
]
|
||||
|
|
@ -383,7 +383,6 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
|||
|
||||
# todo: recalculate toque_number
|
||||
def recalculate_toque_number(self):
|
||||
import ipdb; ipdb.set_trace()
|
||||
toque_number = None
|
||||
if self.address and self.public_mark:
|
||||
toque_number = RatingStrategy.objects. \
|
||||
|
|
@ -681,8 +680,10 @@ class RatingStrategyManager(models.Manager):
|
|||
|
||||
def get_toque_number(self, country, public_mark):
|
||||
"""Get toque number for country and public_mark."""
|
||||
obj = self.model.objects.by_country(country). \
|
||||
for_public_mark(public_mark).first()
|
||||
qs = self.model.objects.by_country(country)
|
||||
if not qs.exists():
|
||||
qs = self.model.objects.by_country(None)
|
||||
obj = qs.for_public_mark(public_mark).first()
|
||||
if obj:
|
||||
return obj.toque_number
|
||||
return None
|
||||
|
|
@ -712,7 +713,8 @@ class RatingStrategy(ProjectBaseMixin):
|
|||
(5, _('Five')),
|
||||
)
|
||||
|
||||
country = models.ForeignKey('location.Country', on_delete=models.CASCADE,
|
||||
country = models.ForeignKey('location.Country', null=True, blank=True,
|
||||
default=None, on_delete=models.CASCADE,
|
||||
verbose_name=_('Country'))
|
||||
toque_number = models.IntegerField(choices=TOQUE_NUMBER_CHOICES)
|
||||
public_mark_min_value = models.IntegerField()
|
||||
|
|
@ -725,4 +727,9 @@ class RatingStrategy(ProjectBaseMixin):
|
|||
|
||||
verbose_name = _('Rating strategy')
|
||||
verbose_name_plural = _('Rating strategy')
|
||||
unique_together = ('country', 'toque_number')
|
||||
unique_together = ('country', 'toque_number')
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.country.code if self.country else "Other country"}. ' \
|
||||
f'"{self.toque_number}": {self.public_mark_min_value}-' \
|
||||
f'{self.public_mark_max_value}'
|
||||
Loading…
Reference in New Issue
Block a user