Comments (6)
@BustDot the DB name should be customizable in the constructor function, this feature should be supported. See other adapter as example: https://github.com/pycasbin/pymongo-adapter#simple-example
from django-orm-adapter.
@BustDot the DB name should be customizable in the constructor function, this feature should be supported. See other adapter as example: https://github.com/pycasbin/pymongo-adapter#simple-example
I will look into it.
from django-orm-adapter.
@techoner @Nekotoxin
from django-orm-adapter.
The django docs illustrate how to use another databases.
Since the django-orm-adapter uses the default databases, you can add a database argument for the adapter and change the code whenever interacting with the django-orm.
For example(I'm not sure whether it is correct, just for demonstration):
def save_policy(self, model):
"""saves all policy rules to the storage."""
# See https://casbin.org/docs/en/adapters#autosave
# for why this is deleting all rules
CasbinRule.objects.using("account").all().delete()
lines = []
for sec in ["p", "g"]:
if sec not in model.model.keys():
continue
for ptype, ast in model.model[sec].items():
for rule in ast.policy:
lines.append(self._create_policy_line(ptype, rule))
CasbinRule.objects.using("account").bulk_create(lines)
return True
from django-orm-adapter.
The django docs illustrate how to use another databases.
Since the django-orm-adapter uses the default databases, you can add a database argument for the adapter and change the code whenever interacting with the django-orm.
For example(I'm not sure whether it is correct, just for demonstration):
def save_policy(self, model): """saves all policy rules to the storage.""" # See https://casbin.org/docs/en/adapters#autosave # for why this is deleting all rules CasbinRule.objects.using("account").all().delete() lines = [] for sec in ["p", "g"]: if sec not in model.model.keys(): continue for ptype, ast in model.model[sec].items(): for rule in ast.policy: lines.append(self._create_policy_line(ptype, rule)) CasbinRule.objects.using("account").bulk_create(lines) return True
NOT save, but how to initialize_enforcer() with other DB_ALIAS:
https://github.com/pycasbin/django-orm-adapter/blob/master/casbin_adapter/enforcer.py
from django-orm-adapter.
still error
initialize_enforcer() first called here:
https://github.com/pycasbin/django-orm-adapter/blob/master/casbin_adapter/apps.py
from django-orm-adapter.
Related Issues (9)
- Status/need help? HOT 5
- Replace Travis CI with GitHub Actions and setup semantic-release HOT 3
- Casbin lib incompatibility HOT 2
- CASBIN_LOG_ENABLED not working HOT 5
- bug: CASBIN_DB_ALIAS not work HOT 4
- `semantic-release-pypi@^3.0.0` uses the `pyproject.toml` based build system interface, if a `pyproject.toml` file exists HOT 3
- Fix the Travis CI build error HOT 3
- in pypi i can't find this package, this repo has another name? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-orm-adapter.