Re: updating a single field / attribute, is it possible? or better practices?
In the meantime, creating and executing your own update command is not difficult. Here is a snippet for a custom PositionField that updates itself when necessary with an SQL UPDATE: http://www.djangosnippets.org/snippets/884/ --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: updating a single field / attribute, is it possible? or better practices?
Exactly. Thanks for the reference. -- oMat On Oct 31, 6:54 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Fri, Oct 31, 2008 at 12:39 PM, omat <[EMAIL PROTECTED]> wrote: > > > Hi all, > > > Is it possible to update a chosen subset of attributes of a model > > instance? > > http://code.djangoproject.com/ticket/4102 > > asks for this, I believe. > > Karen --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: updating a single field / attribute, is it possible? or better practices?
On Fri, Oct 31, 2008 at 12:39 PM, omat <[EMAIL PROTECTED]> wrote: > > Hi all, > > Is it possible to update a chosen subset of attributes of a model > instance? > http://code.djangoproject.com/ticket/4102 asks for this, I believe. Karen --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
updating a single field / attribute, is it possible? or better practices?
Hi all, Is it possible to update a chosen subset of attributes of a model instance? In my case, the view function saves a model instance which was updated in the model's custom save() method. Thus, the update by the save() is overridden. Pseudo code of the scenario: class MyModel(Model): qualified = models.BooleanField() count = models.IntegerField() def save(self): self.count = self.refmodel_set.count(qualified=True) super(...).save() class RefModel(Model): my_model = models.ForeignKey(MyModel) def form_view(request, id): my_instance = MyModel.objects.get(id=id) ref_form = RefForm(data) if ref_form.is_valid(): ref = ref_form.save(commit=False) ref.my_model = my_instance ref.save() if ref.some_attribute: my_instance.qualified = True my_instance.save() # this overrides the change made in MyModel.save() I thought, if there is a way to save only a single attribute, without touching others, my problem will be solved. In that case, the last two lines would look like: my_instance.qualified = True my_instance.save(fields=('qualified',)) Does this makes sense? Thanks for any comments, oMat --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---