Coder Social home page Coder Social logo

Comments (6)

hsluoyz avatar hsluoyz commented on June 13, 2024 1

@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

image

from django-orm-adapter.

BustDot avatar BustDot commented on June 13, 2024 1

@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

image

I will look into it.

from django-orm-adapter.

casbin-bot avatar casbin-bot commented on June 13, 2024

@techoner @Nekotoxin

from django-orm-adapter.

BustDot avatar BustDot commented on June 13, 2024

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.

hefeiyun avatar hefeiyun commented on June 13, 2024

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.

hefeiyun avatar hefeiyun commented on June 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.