add trensfer menus
This commit is contained in:
parent
9d3e278763
commit
db6c93a72f
|
|
@ -79,6 +79,7 @@ class PlateInline(admin.TabularInline):
|
||||||
class MenuAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
class MenuAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
||||||
"""Menu admin."""
|
"""Menu admin."""
|
||||||
list_display = ['id', 'category_translated']
|
list_display = ['id', 'category_translated']
|
||||||
|
raw_id_fields = ['establishment']
|
||||||
inlines = [
|
inlines = [
|
||||||
PlateInline,
|
PlateInline,
|
||||||
]
|
]
|
||||||
|
|
|
||||||
32
apps/establishment/management/commands/add_menus.py
Normal file
32
apps/establishment/management/commands/add_menus.py
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from establishment.models import Establishment, Menu, Plate
|
||||||
|
from transfer.models import Menus
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Add menus from old db to new db'
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
count = 0
|
||||||
|
menus = Menus.objects.filter(name__isnull=False).exclude(name='')
|
||||||
|
for old_menu in menus:
|
||||||
|
est = Establishment.objects.filter(
|
||||||
|
old_id=old_menu.establishment_id).first()
|
||||||
|
if est:
|
||||||
|
|
||||||
|
menu, _ = Menu.objects.get_or_create(
|
||||||
|
category={"en-GB": 'FORMULAS'},
|
||||||
|
establishment=est
|
||||||
|
)
|
||||||
|
plate, created = Plate.objects.get_or_create(
|
||||||
|
name={"en-GB": old_menu.name},
|
||||||
|
menu=menu,
|
||||||
|
price=old_menu.price or 0
|
||||||
|
)
|
||||||
|
if created:
|
||||||
|
plate.currency_code = old_menu.currency
|
||||||
|
plate.save()
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
self.stdout.write(self.style.WARNING(f'Updated/created {count} objects.'))
|
||||||
18
apps/establishment/migrations/0052_plate_currency_code.py
Normal file
18
apps/establishment/migrations/0052_plate_currency_code.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-11-03 20:50
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0051_auto_20191101_0732'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='plate',
|
||||||
|
name='currency_code',
|
||||||
|
field=models.CharField(blank=True, default=None, max_length=250, null=True, verbose_name='currency code'),
|
||||||
|
),
|
||||||
|
]
|
||||||
19
apps/establishment/migrations/0053_auto_20191103_2051.py
Normal file
19
apps/establishment/migrations/0053_auto_20191103_2051.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-11-03 20:51
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0052_plate_currency_code'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='plate',
|
||||||
|
name='currency',
|
||||||
|
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='main.Currency', verbose_name='currency'),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
apps/establishment/migrations/0054_auto_20191103_2117.py
Normal file
18
apps/establishment/migrations/0054_auto_20191103_2117.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-11-03 21:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0053_auto_20191103_2051'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='plate',
|
||||||
|
name='is_signature_plate',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='is signature plate'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -628,9 +628,12 @@ class Plate(TranslatedFieldsMixin, models.Model):
|
||||||
help_text='{"en-GB":"some text"}')
|
help_text='{"en-GB":"some text"}')
|
||||||
price = models.DecimalField(
|
price = models.DecimalField(
|
||||||
_('price'), max_digits=14, decimal_places=2)
|
_('price'), max_digits=14, decimal_places=2)
|
||||||
is_signature_plate = models.BooleanField(_('is signature plate'))
|
is_signature_plate = models.BooleanField(_('is signature plate'), default=False)
|
||||||
currency = models.ForeignKey(
|
currency = models.ForeignKey(
|
||||||
'main.Currency', verbose_name=_('currency'), on_delete=models.CASCADE)
|
'main.Currency', verbose_name=_('currency'), on_delete=models.CASCADE,
|
||||||
|
blank=True, null=True, default=None)
|
||||||
|
currency_code = models.CharField(
|
||||||
|
_('currency code'), max_length=250, blank=True, null=True, default=None)
|
||||||
|
|
||||||
menu = models.ForeignKey(
|
menu = models.ForeignKey(
|
||||||
'establishment.Menu', verbose_name=_('menu'), on_delete=models.CASCADE)
|
'establishment.Menu', verbose_name=_('menu'), on_delete=models.CASCADE)
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,10 @@ class AwardAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.Currency)
|
@admin.register(models.Currency)
|
||||||
class CurrencContentAdmin(admin.ModelAdmin):
|
class CurrencyContentAdmin(admin.ModelAdmin):
|
||||||
"""CurrencContent admin"""
|
"""Currency Content admin"""
|
||||||
|
list_display = ['id', 'slug', 'code']
|
||||||
|
list_display_links = ['slug']
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.Carousel)
|
@admin.register(models.Carousel)
|
||||||
|
|
|
||||||
23
apps/main/migrations/0031_auto_20191103_2037.py
Normal file
23
apps/main/migrations/0031_auto_20191103_2037.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-11-03 20:37
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0030_auto_20191103_1350'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='currency',
|
||||||
|
name='code',
|
||||||
|
field=models.CharField(default=None, max_length=5, null=True, unique=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='currency',
|
||||||
|
name='slug',
|
||||||
|
field=models.SlugField(max_length=5, unique=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -25,7 +25,8 @@ class Currency(TranslatedFieldsMixin, models.Model):
|
||||||
_('name'), null=True, blank=True,
|
_('name'), null=True, blank=True,
|
||||||
default=None, help_text='{"en-GB":"some text"}')
|
default=None, help_text='{"en-GB":"some text"}')
|
||||||
sign = models.CharField(_('sign'), max_length=255)
|
sign = models.CharField(_('sign'), max_length=255)
|
||||||
slug = models.SlugField(max_length=255, unique=True)
|
slug = models.SlugField(max_length=5, unique=True)
|
||||||
|
code = models.CharField(max_length=5, unique=True, null=True, default=None)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('currency')
|
verbose_name = _('currency')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user