social choices model
This commit is contained in:
parent
906ca921f5
commit
b94a6dfd62
|
|
@ -96,3 +96,14 @@ class MenuAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
||||||
@admin.register(models.RatingStrategy)
|
@admin.register(models.RatingStrategy)
|
||||||
class RatingStrategyAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
class RatingStrategyAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
||||||
"""Admin conf for Rating Strategy model."""
|
"""Admin conf for Rating Strategy model."""
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.SocialChoice)
|
||||||
|
class SocialChoiceAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
||||||
|
"""Admin conf for SocialChoice model."""
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.SocialNetwork)
|
||||||
|
class SocialNetworkAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
||||||
|
"""Admin conf for SocialNetwork model."""
|
||||||
|
raw_id_fields = ('establishment',)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from establishment.models import Establishment, SocialNetwork
|
from establishment.models import Establishment, SocialChoice, SocialNetwork
|
||||||
from transfer.models import EstablishmentInfos
|
from transfer.models import EstablishmentInfos
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -10,46 +10,47 @@ class Command(BaseCommand):
|
||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
|
facebook, _ = SocialChoice.objects.get_or_create(title='facebook')
|
||||||
|
twitter, _ = SocialChoice.objects.get_or_create(title='twitter')
|
||||||
|
instagram, _ = SocialChoice.objects.get_or_create(title='instagram')
|
||||||
|
|
||||||
queryset = EstablishmentInfos.objects.exclude(
|
queryset = EstablishmentInfos.objects.exclude(
|
||||||
establishment_id__isnull=True
|
establishment_id__isnull=True
|
||||||
).values_list('id', 'establishment_id', 'facebook', 'twitter', 'instagram')
|
).values_list('id', 'establishment_id', 'facebook', 'twitter', 'instagram')
|
||||||
|
|
||||||
for id, es_id, facebook, twitter, instagram in queryset:
|
for id, es_id, facebook_url, twitter_url, instagram_url in queryset:
|
||||||
try:
|
|
||||||
establishment = Establishment.objects.get(old_id=es_id)
|
|
||||||
except Establishment.DoesNotExist:
|
|
||||||
continue
|
|
||||||
except Establishment.MultipleObjectsReturned:
|
|
||||||
establishment = Establishment.objects.filter(old_id=es_id).first()
|
establishment = Establishment.objects.filter(old_id=es_id).first()
|
||||||
else:
|
if not establishment:
|
||||||
if facebook:
|
continue
|
||||||
if 'facebook.com/' not in facebook:
|
|
||||||
facebook = 'https://www.facebook.com/' + facebook
|
if facebook_url:
|
||||||
|
if 'facebook.com/' not in facebook_url:
|
||||||
|
facebook_url = 'https://www.facebook.com/' + facebook_url
|
||||||
obj, _ = SocialNetwork.objects.get_or_create(
|
obj, _ = SocialNetwork.objects.get_or_create(
|
||||||
old_id=id,
|
old_id=id,
|
||||||
establishment=establishment,
|
establishment=establishment,
|
||||||
title='facebook',
|
network=facebook,
|
||||||
url=facebook,
|
url=facebook_url,
|
||||||
)
|
)
|
||||||
count += 1
|
count += 1
|
||||||
if twitter:
|
if twitter_url:
|
||||||
if 'twitter.com/' not in twitter:
|
if 'twitter.com/' not in twitter_url:
|
||||||
twitter = 'https://www.twitter.com/' + twitter
|
twitter_url = 'https://www.twitter.com/' + twitter_url
|
||||||
obj, _ = SocialNetwork.objects.get_or_create(
|
obj, _ = SocialNetwork.objects.get_or_create(
|
||||||
old_id=id,
|
old_id=id,
|
||||||
establishment=establishment,
|
establishment=establishment,
|
||||||
title='twitter',
|
network=twitter,
|
||||||
url=twitter,
|
url=twitter_url,
|
||||||
)
|
)
|
||||||
count += 1
|
count += 1
|
||||||
if instagram:
|
if instagram_url:
|
||||||
if 'instagram.com/' not in instagram:
|
if 'instagram.com/' not in instagram_url:
|
||||||
instagram = 'https://www.instagram.com/' + instagram
|
instagram = 'https://www.instagram.com/' + instagram_url
|
||||||
obj, _ = SocialNetwork.objects.get_or_create(
|
obj, _ = SocialNetwork.objects.get_or_create(
|
||||||
old_id=id,
|
old_id=id,
|
||||||
establishment=establishment,
|
establishment=establishment,
|
||||||
title='instagram',
|
network=instagram,
|
||||||
url=instagram,
|
url=instagram_url,
|
||||||
)
|
)
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
|
|
||||||
35
apps/establishment/migrations/0061_auto_20191114_0550.py
Normal file
35
apps/establishment/migrations/0061_auto_20191114_0550.py
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Generated by Django 2.2.7 on 2019-11-14 05:50
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0060_auto_20191113_1512'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SocialChoice',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('title', models.CharField(max_length=255, unique=True, verbose_name='title')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'social choice',
|
||||||
|
'verbose_name_plural': 'social choices',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='socialnetwork',
|
||||||
|
name='title',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='socialnetwork',
|
||||||
|
name='network',
|
||||||
|
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='social_links', to='establishment.SocialChoice', verbose_name='social network'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -740,12 +740,31 @@ class Menu(TranslatedFieldsMixin, BaseAttributes):
|
||||||
verbose_name_plural = _('menu')
|
verbose_name_plural = _('menu')
|
||||||
|
|
||||||
|
|
||||||
|
class SocialChoice(models.Model):
|
||||||
|
title = models.CharField(_('title'), max_length=255, unique=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('social choice')
|
||||||
|
verbose_name_plural = _('social choices')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
class SocialNetwork(models.Model):
|
class SocialNetwork(models.Model):
|
||||||
old_id = models.PositiveIntegerField(_('old id'), blank=True, null=True, default=None)
|
old_id = models.PositiveIntegerField(_('old id'), blank=True, null=True, default=None)
|
||||||
establishment = models.ForeignKey(
|
establishment = models.ForeignKey(
|
||||||
'Establishment', verbose_name=_('establishment'),
|
'Establishment',
|
||||||
related_name='socials', on_delete=models.CASCADE)
|
verbose_name=_('establishment'),
|
||||||
title = models.CharField(_('title'), max_length=255)
|
related_name='socials',
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
network = models.ForeignKey(
|
||||||
|
SocialChoice,
|
||||||
|
verbose_name=_('social network'),
|
||||||
|
related_name='social_links',
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
url = models.URLField(_('URL'), max_length=255)
|
url = models.URLField(_('URL'), max_length=255)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
@ -753,7 +772,7 @@ class SocialNetwork(models.Model):
|
||||||
verbose_name_plural = _('social networks')
|
verbose_name_plural = _('social networks')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return f'{self.network.title}: {self.url}'
|
||||||
|
|
||||||
|
|
||||||
class RatingStrategyManager(models.Manager):
|
class RatingStrategyManager(models.Manager):
|
||||||
|
|
|
||||||
18
apps/review/migrations/0015_review_mark.py
Normal file
18
apps/review/migrations/0015_review_mark.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.7 on 2019-11-13 09:44
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('review', '0014_auto_20191112_0538'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='review',
|
||||||
|
name='mark',
|
||||||
|
field=models.FloatField(blank=True, default=None, null=True, verbose_name='mark'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -70,6 +70,7 @@ class Review(BaseAttributes, TranslatedFieldsMixin):
|
||||||
null=True)
|
null=True)
|
||||||
|
|
||||||
old_id = models.PositiveIntegerField(_('old id'), blank=True, null=True, default=None)
|
old_id = models.PositiveIntegerField(_('old id'), blank=True, null=True, default=None)
|
||||||
|
mark = models.FloatField(verbose_name=_('mark'), blank=True, null=True, default=None)
|
||||||
|
|
||||||
objects = ReviewQuerySet.as_manager()
|
objects = ReviewQuerySet.as_manager()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user