python - save() takes at least 2 arguments (1 given) -


i'm trying send email out once field changed. i've done research , seen lot of solution similar issues none seems solve problem.

it seems issue comes fact define 'user' @ start of save method. please!

class countrylist(model.models):     score= models.positivesmallintegerfield(null=true, blank = true, choices=zip(range(1, 11), range(1, 11)))       country = models.charfield(max_length=100, null =true, blank=true)        def save(self, user, *args, **kwargs):           old_countrylist = countrylist.objects.get(pk=self.id)             if old_countrylist.score!= self.score:              send_mail('the user ' + user.username + ' has changed score ' + self.country \                   + 'from ' + str(old_countrylist.score) + ' '                    \                   + str(self.score) + '.\nthis change made @ '                       \                   + str(datetime.datetime.now())[:19] + '. \n\nlink change: http://'         \                   + socket.gethostname() + '/home/countries/' + str(self.id),           # email body                   'some_email_here',                                                 # send                   settings.email_recipients,                                                   # send                   fail_silently=false)           super(countrylist, self).save(*args, **kwargs) # call "real" save()  

django's model api expects model.save() sticks defined signature, quite few other parts of framework, contribs , third part apps rely on this.

also sending mails model.save() method terrible idea... have understand models (and must remain) strictly decoupled http request (views...) cycle - may modified other code (think custom management commands etc) , won't have "current user" @ hand (nor want send mails anyone).

in case since you're concerned changed made thru app's views mail should send view itself.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -