Re: Is there a way to tell an instance was saved without checking instalce.pk or doing a db lookup?
On Sun, May 26, 2013 at 8:35 PM, Marc R <warath@gmail.com> wrote:
-- What are you trying to accomplish?
Just wanted to see if there is a one-liner for checking if the object has been saved. Checking for .pk is usually fine, except for those rare cases when pk is set manually. No bid deal. Thank you for responding.
On Saturday, May 25, 2013 4:01:29 PM UTC-4, Sergiy wrote:To check if the instance was saved one might do something like this:def is_instance_saved(instance):if instance.pk is None:return False# in case pk was set manuallyreturn TrueI wonder if the instance already knows whether it was saved or not (through some sort of private attribute).
ThanksSergiy
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home