This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.models import AbstractUser | |
from django.contrib.auth.models import UserManager | |
class CustomUser(AbstractUser): | |
objects = UserManager() | |
class Meta: | |
app_label = "goibibo_inbuilt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.apps import apps | |
from django.db import models | |
from django.contrib.contenttypes.models import ContentTypeManager | |
from django.utils.translation import gettext_lazy as _ | |
class CustomContentType(models.Model): | |
app_label = models.CharField(max_length=100) | |
model = models.CharField(_('python model class name'), max_length=100) | |
objects = ContentTypeManager() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
from collections import defaultdict | |
from django.core import checks | |
from django.core.exceptions import FieldDoesNotExist, ObjectDoesNotExist | |
from django.db import models | |
from django.utils.encoding import python_2_unicode_compatible | |
from custom_contenttypes import CustomContentType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HulkDataRouter(object): | |
""" | |
A router to control all database operations on models | |
""" | |
def db_for_read(self, model, **hints): | |
if model._meta.app_label in ['goibibo_models', 'goibibo_inbuilt']: | |
return 'old_db' | |
else: | |
return 'hulk_db' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example: | |
# from custom_user import CustomUser | |
# from custom_contenttype import CustomContentType | |
# from custom_genericcontenttypes import CustomGenericForeignKey | |
class Notes(models.Model): | |
notes = models.TextField() | |
createdon = models.DateTimeField(auto_now_add=True) | |
modifiedon = models.DateTimeField(auto_now=True) | |
user = models.ForeignKey(CustomUser) | |
content_type = models.ForeignKey(CustomContentType) |