Created
June 4, 2019 20:39
-
-
Save brylor/bb4ec571ba2847dcda9533127e6944f3 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
from django.contrib import admin | |
from .models import AccountModel | |
#class AccountAdmin(admin.ModelAdmin): | |
#account_id = models.CharField(max_length=10) | |
class AccountAdmin(admin.ModelAdmin): | |
search_fields = ['account_id'] | |
list_display = ['account_id',] | |
list_per_page = 50 | |
admin.site.register(AccountModel,AccountAdmin) |
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 django.db import models | |
from cassandra.cqlengine import columns | |
from django_cassandra_engine.models import DjangoCassandraModel | |
class AccountRouter(object): | |
def db_for_read(self, model, **hints): | |
"Point all operations on account models to 'accountdb'" | |
if model._meta.app_label == 'accounts': | |
return 'accountdb' | |
return 'default' | |
def db_for_write(self, model, **hints): | |
"Point all operations on account models to 'accountdb'" | |
if model._meta.app_label == 'accounts': | |
return 'accountdb' | |
return 'default' | |
def allow_relation(self, obj1, obj2, **hints): | |
"Allow any relation if a both models in account app" | |
if obj1._meta.app_label == 'accounts' and obj2._meta.app_label == 'accounts': | |
return True | |
# Allow if neither is account app | |
elif 'accounts' not in [obj1._meta.app_label, obj2._meta.app_label]: | |
return True | |
return False | |
def allow_syncdb(self, db, model): | |
if db == 'accountdb' or model._meta.app_label == "accounts": | |
return False # we're not using syncdb on our legacy database | |
else: # but all other models/databases are fine | |
return True | |
class AccountModel(DjangoCassandraModel): | |
account_id = columns.Text(primary_key=True, index=True) | |
divison_id = columns.Text() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment