gault-millau/apps/transfer/mixins.py
littlewolf 9dcdb7575e Switch application
Add application command
Update mixin
Add mixin to models
2019-10-02 11:41:14 +03:00

25 lines
589 B
Python

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