Skip to content

Instantly share code, notes, and snippets.

View nehajagadeesh's full-sized avatar

Neha nehajagadeesh

  • Goibibo
View GitHub Profile
# 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)
@nehajagadeesh
nehajagadeesh / multiple_db_routers.py
Created March 7, 2018 14:13
Multiple Data Routers
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'
@nehajagadeesh
nehajagadeesh / generic_contenttypes.py
Created March 7, 2018 13:27
Generic Contenttypes
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
@nehajagadeesh
nehajagadeesh / custom_contenttype.py
Created March 7, 2018 13:25
Custom Contenttype
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()
@nehajagadeesh
nehajagadeesh / custom_user.py
Last active March 7, 2018 13:21
Custom User
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"