Thanks James, I like that idea. I'll experiment with it. Have used Proxies 
before just not with this in mind.

On Sunday, 3 June 2018 15:06:41 UTC+10, James Schneider wrote:
>
>
>
> On Sat, Jun 2, 2018, 6:14 PM Bernd Wechner <bernd....@gmail.com 
> <javascript:>> 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/9d3b3b83-d529-4fc9-bcd0-8b2bda690075%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to