27 lines
692 B
Python
27 lines
692 B
Python
from django.db import models
|
|
from django.forms.models import model_to_dict
|
|
|
|
|
|
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, fields):
|
|
model_dict = model_to_dict(self, fields)
|
|
print(getattr(self, "using", "Using not found"))
|
|
|
|
class Meta:
|
|
abstract = True
|