Created
March 21, 2013 06:55
-
-
Save hirokazumiyaji/5211187 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 | |
import re | |
class PlayerShardRouter(object): | |
regex_app = re.compile('.*player.*') | |
regex_db = re.compile('.*shard.*') | |
def get_shard(self, playe_id): | |
return 'shard' | |
def db_for_read(self, model, **hints): | |
if self.regex_app.match(model._meta.app_label): | |
return self.get_shard(model.player_id) | |
return None | |
def db_for_write(self, model, **hints): | |
if self.regex_app.match(model._meta.app_label): | |
return self.get_shard(model.player_id) | |
return None | |
def allow_relation(self, obj1, obj2, **hints): | |
if self.regex_app.match(obj1._meta.app_label) or self.regex_app.match(obj2._meta.app_label): | |
return True | |
return None | |
def allow_syncdb(self, db, model): | |
if regex_db.match(db): | |
return regex_app.match(model._meta.app_label) | |
elif regex_app.match(model._meta.app_label): | |
return False | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment