Skip to content

Instantly share code, notes, and snippets.

@jourdanrodrigues
Last active April 25, 2020 16:19
Show Gist options
  • Save jourdanrodrigues/e4899b2ddb100111d75ede2f6a5d5924 to your computer and use it in GitHub Desktop.
Save jourdanrodrigues/e4899b2ddb100111d75ede2f6a5d5924 to your computer and use it in GitHub Desktop.
from django.db import models
from django.db.models import QuerySet
# The value is the key that goes in the `DATABASES` settings.
# Ideally set in the Django settings as well, so it can be project-wide accessible
SOURCE_DB_LABEL = 'source_db'
class SourceServiceQuerySet(QuerySet):
def as_manager(cls):
return super().as_manager().db_manager(SOURCE_DB_LABEL)
as_manager.queryset_only = True
as_manager = classmethod(as_manager)
class SourceServiceModel(models.Model):
objects = SourceServiceQuerySet.as_manager()
class Meta:
abstract = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment