Ticket #5417: mult_update_partial.diff

File mult_update_partial.diff, 1.0 KB (added by deepak <deep.thukral@…>, 17 years ago)

need testing doing part1

  • db/models/query.py

     
    379379        "Returns a new QuerySet instance with the args ANDed to the existing set."
    380380        return self._filter_or_exclude(None, *args, **kwargs)
    381381
     382    def update(self, *args, **kwargs):
     383        "Updates records in queryset"
     384        assert len(kwargs), 'update() must be passed at least one keyword argument'
     385        for obj in self:
     386            for k, v in kwargs.items():
     387                if '__' not in k:
     388                    assert k in [f.column for f in obj._meta.fields], 'update() should contain a valid field name, %s Does not exist.' % k
     389                    setattr(obj, k, v)
     390            obj.save()
     391        return self
     392       
     393
    382394    def exclude(self, *args, **kwargs):
    383395        "Returns a new QuerySet instance with NOT (args) ANDed to the existing set."
    384396        return self._filter_or_exclude(QNot, *args, **kwargs)
Back to Top