Featured post
python - Read-only Django object manager? -
i doing agressive caching , i'd make sure nobody accidentally writes code updates database directly. imagine way solve rename normal object manager .rw_objects
caches use, , replace .objects
manager logs warning on non-updating access , throws exception if tries update it.
i've written object manager , query set i'm not sure how go checking whether query updating database.
any suggestions?
i'm thinking 2 approaches here.
create custom manager, override
_insert()
,_update()
raise exception / log query, ,get_query_set()
return custom queryset overridescreate()
,get_or_create()
, ,update()
.if you're using django 1.2, create database connection in
settings.py
call"read_only"
, , create custom manager returns querset using connection (likedef get_query_set() return super(readonlymanager, self).get_query_set().using("read_only")
, , mark connection read-only. (one way create read-only user database connection"read_only"
.... if you're using postgres, can stuff how create read-only user in postgresql?)
- Get link
- X
- Other Apps
Comments
Post a Comment