我想获取名为“some_attribute”的表单字段的值。我试试这个self.Meta.model.some_attribute
:
class TestModel(models.Model):
some_attribute = models.CharField(max_length=255)
class TestForm(forms.ModelForm):
def save(self, *args, **kwargs):
super(TestForm, self).save(*args, **kwargs)
send_mail('topic', self.Meta.model.some_attribute, 'xxx@yyyy.com', ['xxx@yyyy.com'],
fail_silently=False)
class Meta:
model = TestModel
这会导致错误:“EnrollInEventForm”对象没有属性“some_attribute”。我怎么做?