Sunday, May 27, 2012

Re: Database Query in Shell

On Sun, May 27, 2012 at 6:05 PM, <mgc_django-users@chamberlain.net.au> wrote:

> To get a queryset containing all the objects where field == other_field
> should be something like the following:
>
> from django.db.models import F
>
> Amounts.objects.filter(field = F("other_field"))
>
> to then update all those objects with "OTHER" as the value for field would
> be:
>
> Amounts.objects.filter(field = F("other_field")).update(field="OTHER")
>
> Note that this won't execute the "else" portion above, but as it is not
> making any change (field already equals field), I assume this isn't an
> issue.
>
You are great, sir.
Thank you.
The query successfully updated the field column as was required.

--
Sandeep Kaur
E-Mail: mkaurkhalsa@gmail.com
Blog: sandymadaan.wordpress.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment