django


Save with update_fields did not affect any rows (while changing class)


Let's have a model with decorator:
def upgradable(model):
#classmethod
def upgrade(cls, base, **kwargs):
base.__class__ = cls
for attr, value in kwargs.items():
setattr(base, attr, value)
return base
setattr(model, "upgrade", upgrade)
return model
class Person(models.Model):
name = models.CharField(max_length=50)
def save(self, *args, **kwargs):
self.name = self.name.upper()
super(Person, self).save(*args, **kwargs)
and inherited model:
#upgradable
class User(Person):
email = models.EmailField();
and I'm trying to upgrade
person = Person.objects.get(...)
user = User.upgrade(person, email="example#example.com")
user.save()
But the error appears:
Save with update_fields did not affect any rows.
in connection to super(Person, self).save(*args, **kwargs) (in method save of model person)
It isn't total wrong, because indeed I don't want to change anything in table person, I just want to add something to table user (pointer to person and email).
So how to skip this warning?
The answer wasn't obvious - I tried to add
user.save(force_update = True)
but it isn't work.
But
user.save(force_insert = True)
do the job. Strange, but works.

Related Links

Form Wizard: error undefined variables
Sync Fabric with South
“No module named balanced_django.middleware”
Django Invalid Form, Keeping the Next Parameter
How to link to an .ipa file (over the air ios app installation) using django and STATIC_URL?
Pulling out a product only once from a django view
How to translate a message/variable in Django templates?
Getting the selected value on a Django forms.ChoiceField
django dynamic data driven form fields [duplicate]
django best practice query foreign key
Sphinx documentation of django tests
Django resize image during upload [closed]
object has no attribute 'result_count'
Django 1.5 NoReverseMatch at /blog/
django-social-auth backend not found
Django: save model object of a ModelForm

Categories

HOME
android
go
asp.net-web-api
cygwin
phantom-dsl
paraview
checkstyle
mysql-workbench
themes
jsf-2.2
rendering
appcelerator
nfs
performancepoint
syntaxnet
categorical-data
endeca
mautic
opengl-es-3.0
frequency-distribution
qsqlquery
package-managers
intershop
replication
drive
dataflow-diagram
imageresizer
beta
expressionengine3
windows-server-2003
itunes
moses
maze
bulletphysics
linked-data
angular-translate
cppreference
finagle
record
database-comparison
papaparse
gojs
yowsup
magento-1.9.2.4
sessionstorage
bc
metaprogramming
postgresql-8.4
opennms
podscms
corruption
qtranslate
yii2-user
backbone-collections
ngmaterial
er-diagram
janus
actor-platform
respondcms
swizzling
riot
createprocess
toast
concept-insights
forwarding
morton-number
rubaxa-sortable
extjs-grid
canalyzer
dulwich
shopizer
cryptographichashfunction
sql-scripts
spy++
iso-prolog
template-deduction
tinyxml
multitasking
embedded-fonts
kogrid
nebula
dolby-audio-api
web-notifications
robotlegs
dopostback
qi4j
lambdaj
window-decoration
failing-tests
virtualpathprovider
automationelement
tournament
dataform
silverlight-oob
wcf-instancing
scrubyt

Resources

Encrypt Message