how to not saving models

0 views
Skip to first unread message

ReneMarxis

unread,
Jun 23, 2009, 6:50:33 AM6/23/09
to Django users
Hello

i have a question if something is possible to implement :)

i need some demo functionality in my django app and i'd like to
realize it by having some flag in the user's session that defines if
data should be saved at all or not in the whole app (for the session
user).

That way i could just create some data (via fixtures) and define some
demo-user and all functionality would be 'visible', but no data could
be changed/saved.

Could something like this be realized in django? Probably with
signals?

Any hints are very welcome.

_rene

ReneMarxis

unread,
Jun 23, 2009, 6:56:19 AM6/23/09
to Django users
what i forgot to say: Of course i don't like to change all models-
code. Some 'global' solution is what i am looking for.

Matías Costa

unread,
Jun 23, 2009, 7:38:38 AM6/23/09
to django...@googlegroups.com
Monkey patch django.db.model.save

Where? in manage.py?

ReneMarxis

unread,
Jun 23, 2009, 9:42:20 AM6/23/09
to Django users
Hey Matias.

Many thanks for your answer. This is what my 'new' manage.py looks
like:

http://dpaste.com/58713/

and it seems to work. At least no data is saved any longer :)

But next question is not far away:
I can use pass or return forig(self) according to if i'd like to save
or not (is this ok at all?), but how can i check session data. There
is no request/response loop right?

PS: Monkey patching... very nice this :)

On 23 Jun., 13:38, Matías Costa <m.costac...@gmail.com> wrote:
> Monkey patch django.db.model.save
> Where? in manage.py?
>

Matías Costa

unread,
Jun 23, 2009, 3:45:37 PM6/23/09
to django...@googlegroups.com
This gets ugglier at each step, think twice before doing this.

Django uses thread storage for django.db.connection, so what seems a simple object is unique to the request and safe. The quick and dirty way is to place a middleware after auth, and set something in django.db.connection.

PD: django.db.connection is the name I recall from memory. May be django.models.db.connection or django.core.db.connection or ... etc
Reply all
Reply to author
Forward
0 new messages