Re: Filtering for an object that is modified in memory loses those modifications?
Thanks for the clarification Skylar and Bill. That all makes sense. Margie On Apr 23, 12:48 pm, Bill Freemanwrote: > This is correct behavior. You do not have a handle on a db row. > You have a reference to an instance of a python class whose > attributes contain data copied from the (set of foreign key and/or > join table related )db row(s). Filter is a means of preparing a new > query to run against the db. When that query is executed (the > filter return is evaluated) a new collection of python class instances > is created and populated from what the db returns for the query. > There is no awareness that you still have a reference to some other > instance. The new instance of the class for the particular row will > have been populated only from the databases. Changes to that > other instance are private to the software holding a reference to it > unless and until you call its save() method -- the save method of > some other instance such as the one from the latter query, won't > do -- at which time the ORM will compose and execute an update > query on the database to set the fields in the row according to the > attribute values of the instance. > > Bill > > On Fri, Apr 23, 2010 at 3:15 PM, Margie Roginski > > > > wrote: > > I have a situation where I have a handle to a db object and I've > > modified a field in it. Then I later end up executing a filter that > > finds that same object (among others) and saves all of the objects it > > finds. In this situation the modified fields do not get saved out. > > It's like the filter is getting the object directly from the database, > > as opposed to getting the object that is in memory and modified (but > > not yet saved). > > > Is this the expected behavior? > > > Margie > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Filtering for an object that is modified in memory loses those modifications?
This is correct behavior. You do not have a handle on a db row. You have a reference to an instance of a python class whose attributes contain data copied from the (set of foreign key and/or join table related )db row(s). Filter is a means of preparing a new query to run against the db. When that query is executed (the filter return is evaluated) a new collection of python class instances is created and populated from what the db returns for the query. There is no awareness that you still have a reference to some other instance. The new instance of the class for the particular row will have been populated only from the databases. Changes to that other instance are private to the software holding a reference to it unless and until you call its save() method -- the save method of some other instance such as the one from the latter query, won't do -- at which time the ORM will compose and execute an update query on the database to set the fields in the row according to the attribute values of the instance. Bill On Fri, Apr 23, 2010 at 3:15 PM, Margie Roginskiwrote: > I have a situation where I have a handle to a db object and I've > modified a field in it. Then I later end up executing a filter that > finds that same object (among others) and saves all of the objects it > finds. In this situation the modified fields do not get saved out. > It's like the filter is getting the object directly from the database, > as opposed to getting the object that is in memory and modified (but > not yet saved). > > Is this the expected behavior? > > Margie > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Filtering for an object that is modified in memory loses those modifications?
Yes. The filter method returns a queryset which is a lazy database object that will query the database to get the queryset. You would have to save the object for the queryset to return it. You could however get all of the objects which are not your select objects MyModel.objects.exclude(pk__in=iterable_of_in_memory_pks_not_to_be_returned) On Apr 23, 3:15 pm, Margie Roginskiwrote: > I have a situation where I have a handle to a db object and I've > modified a field in it. Then I later end up executing a filter that > finds that same object (among others) and saves all of the objects it > finds. In this situation the modified fields do not get saved out. > It's like the filter is getting the object directly from the database, > as opposed to getting the object that is in memory and modified (but > not yet saved). > > Is this the expected behavior? > > Margie > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Filtering for an object that is modified in memory loses those modifications?
I have a situation where I have a handle to a db object and I've modified a field in it. Then I later end up executing a filter that finds that same object (among others) and saves all of the objects it finds. In this situation the modified fields do not get saved out. It's like the filter is getting the object directly from the database, as opposed to getting the object that is in memory and modified (but not yet saved). Is this the expected behavior? Margie -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.