Switch application
Add application command Update mixin Add mixin to models
This commit is contained in:
parent
e3d26b5dd1
commit
9dcdb7575e
|
|
@ -1,7 +1,6 @@
|
||||||
FROM python:3.7
|
FROM python:3.7
|
||||||
ENV PYTHONUNBUFFERED 1
|
ENV PYTHONUNBUFFERED 1
|
||||||
RUN apt-get update; apt-get --assume-yes install binutils libproj-dev gdal-bin gettext
|
RUN apt-get update; apt-get --assume-yes install binutils libproj-dev gdal-bin gettext
|
||||||
RUN apt-get install python3-dev libmysqlclient-dev
|
|
||||||
RUN mkdir /code
|
RUN mkdir /code
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
ADD . /code/
|
ADD . /code/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class MigratesConfig(AppConfig):
|
|
||||||
name = 'migrates'
|
|
||||||
7
apps/transfer/apps.py
Normal file
7
apps/transfer/apps.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
class TransferConfig(AppConfig):
|
||||||
|
name = 'transfer'
|
||||||
|
verbose_name = _('Transfer')
|
||||||
0
apps/transfer/management/commands/__init__.py
Normal file
0
apps/transfer/management/commands/__init__.py
Normal file
20
apps/transfer/management/commands/transfer.py
Normal file
20
apps/transfer/management/commands/transfer.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Transfer data between databases'
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
if options['short']:
|
||||||
|
import __hello__
|
||||||
|
else:
|
||||||
|
import this
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument(
|
||||||
|
'-s',
|
||||||
|
'--short',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Вывод короткого сообщения'
|
||||||
|
)
|
||||||
0
apps/transfer/migrations/__init__.py
Normal file
0
apps/transfer/migrations/__init__.py
Normal file
24
apps/transfer/mixins.py
Normal file
24
apps/transfer/mixins.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class SecondDbManager(models.Manager):
|
||||||
|
def get_queryset(self):
|
||||||
|
qs = super().get_queryset()
|
||||||
|
|
||||||
|
# if `use_db` is set on model use that for choosing the DB
|
||||||
|
if hasattr(self.model, 'use_db'):
|
||||||
|
qs = qs.using(self.model.use_db)
|
||||||
|
|
||||||
|
return qs
|
||||||
|
|
||||||
|
|
||||||
|
class MigrateMixin(models.Model):
|
||||||
|
"""Mixin to data transfer from legacy database"""
|
||||||
|
use_db = 'legacy'
|
||||||
|
objects = SecondDbManager()
|
||||||
|
|
||||||
|
def _parse_instance_fields(self):
|
||||||
|
print(getattr(self, "using", "Using not found"))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
@ -7,8 +7,10 @@
|
||||||
# Feel free to rename the models, but don't rename db_table values or field names.
|
# Feel free to rename the models, but don't rename db_table values or field names.
|
||||||
from django.contrib.gis.db import models
|
from django.contrib.gis.db import models
|
||||||
|
|
||||||
|
from transfer.mixins import MigrateMixin
|
||||||
|
|
||||||
class Cities(models.Model):
|
|
||||||
|
class Cities(MigrateMixin):
|
||||||
using = 'legacy'
|
using = 'legacy'
|
||||||
|
|
||||||
name = models.CharField(max_length=255, blank=True, null=True)
|
name = models.CharField(max_length=255, blank=True, null=True)
|
||||||
|
|
@ -36,7 +38,7 @@ class Cities(models.Model):
|
||||||
unique_together = (('name', 'region_code', 'country_code'),)
|
unique_together = (('name', 'region_code', 'country_code'),)
|
||||||
|
|
||||||
|
|
||||||
class CityNames(models.Model):
|
class CityNames(MigrateMixin):
|
||||||
using = 'legacy'
|
using = 'legacy'
|
||||||
|
|
||||||
name = models.CharField(max_length=100, blank=True, null=True)
|
name = models.CharField(max_length=100, blank=True, null=True)
|
||||||
|
|
@ -51,7 +53,7 @@ class CityNames(models.Model):
|
||||||
unique_together = (('city', 'name', 'locale'),)
|
unique_together = (('city', 'name', 'locale'),)
|
||||||
|
|
||||||
|
|
||||||
class CityPhotos(models.Model):
|
class CityPhotos(MigrateMixin):
|
||||||
using = 'legacy'
|
using = 'legacy'
|
||||||
|
|
||||||
city_id = models.IntegerField(blank=True, null=True)
|
city_id = models.IntegerField(blank=True, null=True)
|
||||||
|
|
@ -71,6 +71,7 @@ PROJECT_APPS = [
|
||||||
'review.apps.ReviewConfig',
|
'review.apps.ReviewConfig',
|
||||||
'comment.apps.CommentConfig',
|
'comment.apps.CommentConfig',
|
||||||
'favorites.apps.FavoritesConfig',
|
'favorites.apps.FavoritesConfig',
|
||||||
|
'transfer.apps.TransferConfig'
|
||||||
]
|
]
|
||||||
|
|
||||||
EXTERNAL_APPS = [
|
EXTERNAL_APPS = [
|
||||||
|
|
@ -91,7 +92,6 @@ EXTERNAL_APPS = [
|
||||||
'rest_framework_simplejwt.token_blacklist',
|
'rest_framework_simplejwt.token_blacklist',
|
||||||
'solo',
|
'solo',
|
||||||
'phonenumber_field',
|
'phonenumber_field',
|
||||||
'apps.migrates'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user