我想获得所选的外键值。 这是我的model.py
models.py
class EmailList(models.Model):
email = models.EmailField(unique=True)
full_name = models.CharField(max_length=120, blank=True, null=True)
def __unicode__(self):
return self.email
class SendEmail(models.Model):
select_email = models.ForeignKey(EmailList)
def __unicode__(self):
return self.select_email.email
admin.py
class SendEmailAdmin(admin.ModelAdmin):
change_form_template = "admin/newsletter/SendEmail/change_form.html"
form = SendEmailForm
def get_form(self, request, obj=None, **kwargs):
if request.method == 'POST':
form = SendEmailForm(request.POST)
if form.is_valid():
# *** Here I want to get selected Foreign key value ***
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
return SendEmailForm
return SendEmailForm
在此代码中我尝试向特定用户发送电子邮件,但我不明白如何获取所选的外键值..plz帮助我。