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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---