以下是类模型,我尝试了the source code但是再次收到错误我需要解释问题save()
方法
from django.conf import settings
from django.core.mail import send_mail
from django.db import models
from django.template.loader import render_to_string
from django.utils import timezone
from cms.models import CMSPlugin
# Create your models here.
class Account(models.Model):
#
# Note: Everything in this section should be optional, fields are to be
# made Required in the Forms.
#
email = models.EmailField(u'Email',
blank=True,
default='',
error_message={'invalid': 'Please enter a correctly formatted email address.'},
help_text=u'Your email address',
max_length=255,
)
password = models.CharField(u'Password',
blank=True,
default='',
error_message={'invalid': 'Please enter your password correctly.'},
help_text=u'Your password more than 6 character',
max_length=255,
)
# Meta, non-form data
created_date = models.DateTimeField(u'created date',
blank=True,
default=timezone.now,
help_text=u'When this person completed the account creation.',
)
was_created = models.BooleanField(u'has been created?',
default=False,
help_text=u'Check this if someone has already reached out to this person.',
)
notes = models.TextField(u'Account notes',
blank=True,
default='',
help_text=u'Internal notes relating to account this person.',
)
referer = models.CharField(u'referring page',
blank=True,
default='',
help_text=u'This is the page the visitor was on before coming to the creating page.'
)
def send_notification_email(self):
"""
Sends a notification email to the list of recipients defined in
settings.NOTIFICATIONS informing them that a new account has arrived.
SERVER_EMAIL is defined in settings and account the "from"
address for email sent from the webserver.
MANAGERS needs to be defined in settings and should be a list
containing the email addresses of those that should receive
notification of an incoming account.
"""
# Using a template is probably overkill for this but...
email_subject = render_to_string('account/notification-subject.txt', {
'account': self,
})
email_body = render_to_string('account/notification-body.txt', {
'account': self,
})
try:
send_email(
email_subject,
email_body,
settings.SERVER_EMAIL,
settings.MANAGERS,
fail_silently=(not settings.DEBUG)
)
except Exception:
# If NOT in DEBUG (development) mode, we silently ignore any
# exceptions to avoid interrupting capture of the submitter'settings
# details. If in DEBUG mode, then raise the error so we can
# troubleshoot.
if (settings.DEBUG):
raise
def save(self, *args, **kwargs):
if not self.pk:
#
# If using something like Celery, then this should be scheduled, not
# executed in the request/response cycle.
#
try:
self.send_notification_email()
except:
#
# This is just a precaution, should there be an issue with the
# emailing, we do not want this to prevent the new Account
# object from being saved.
#
pass
super(Account, self).save(*args, **kwargs)
#models.Model.save(self, *args, **kwargs)
def __unicode__(self):
return '%s (%s)' % (self.email, str(self.created_date), )
class AccountPluginModel(CMSPlugin):
title = models.CharField(u'title',
blank=True,
help_text=u'Optional, Title of the widget.',
max_length=64,
)
错误显示在终端:
File "/home/tarek/Documents/python/teknikcloud-cms/account/models.py", line 91
def save(self, *args, **kwargs):
^
IndentationError: unindent does not match any outer indentation level
我需要解释覆盖save()方法