On Sat, Jun 2, 2018, 6:14 PM Bernd Wechner <bernd.wech...@gmail.com> wrote:

> I'd like to instantiate a model, and play around with it, but ensure it's
> never saved. At bare minimum instantiate it, play around with it then
> delete it, but ideally disable saving somehow. I imagine I can override
> save() on the instance, but am wondering if anyone has experience doing
> this or if there's a canonical method for doing it. I'll experiment but in
> the mean time fishing as I said for experience and any standard methods out
> there.
>

One way to make an obvious indication that the model instance is read-only
is to use a proxy model of the original, with all the saving bits turned
off. Keeps a nice separation of code while utilizing inheritance, and
allows usage of the original/standard behavior.

IMO, overriding the save() method in the proxy model is probably the
cleanest way to prevent an accidental save by a signal, etc.

https://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models

-James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWEjN9M_pmquUpcTASKFtABiWzwtNrK0uHoLW%3D7CnAvpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to