遵循Djangos专家提供的通常很聪明的answer,我想实现我自己的后端,覆盖SQLite3和Postgres JSON处理方法.
我做了什么:
-
把base.py放进go
from django.db.backends.base.operations import BaseDatabaseOperations from django.db.backends.sqlite3.base import DatabaseWrapper as DBW import json class BaseDatabaseOperationsJSON(BaseDatabaseOperations): def adapt_json_value(self, value, encoder): print("should be called") return json.dumps(value, ensure_ascii = False, cls = encoder) class DatabaseWrapper(DBW): ops_class = BaseDatabaseOperationsJSON
-
相应地更改了
settings.py
(我是这样想的):DATABASES = { 'default': { 'ENGINE': "Shelf.backends.sqlite3json", 'NAME': BASE_DIR.joinpath("db.sqlite3"), } }
这将引发错误:
NotImplementedError: subclasses of BaseDatabaseOperations may require a quote_name() method