Python 3.x 如何在django中创建拾取电子邮件字段
我正在创建一个邮件系统管理应用程序。因此,根据附件图,当系统中已经存在我要向其发送电子邮件的客户电子邮件地址时,我希望在A字段中显示他们来自此字段的电子邮件。否则,我们将键入完整的电子邮件地址,然后提交表单。 这是Python 3.x 如何在django中创建拾取电子邮件字段,python-3.x,django,django-templates,Python 3.x,Django,Django Templates,我正在创建一个邮件系统管理应用程序。因此,根据附件图,当系统中已经存在我要向其发送电子邮件的客户电子邮件地址时,我希望在A字段中显示他们来自此字段的电子邮件。否则,我们将键入完整的电子邮件地址,然后提交表单。 这是models.py class Contacts(models.Model): type_Contact_choice=( ('Agent','Agent'), ('Association','Association'), ('A
models.py
class Contacts(models.Model):
type_Contact_choice=(
('Agent','Agent'),
('Association','Association'),
('Autre','Autre'),
('Collectivité','Collectivité'),
('Conseil minicipal','Conseil minicipal'),
('Elu','Elu'),
('Particulier','Particulier'),
('Précture','Précture'),
('Société','Société'),
)
civilite_choice=(
('Monsieur','Monsieur'),
('Madame','Madame'),
('M. et Mme','M. et Mme'),
('Monsieurs','Monsieurs'),
('Mesdames','Mesdames'),
)
category_choice=(
('Personnel','Personnel'),
('Externe','Externe'),
)
nom = models.CharField(max_length=200, null=False)
type_contact = models.CharField(_('Type'), choices=type_Contact_choice, max_length=200, null=True, )
category = models.CharField(_('Catégorie du contact'), choices=category_choice, max_length=50, null=True, blank=True)
prenom = models.CharField(_('Prénom'), max_length=200, null=False)
civilite = models.CharField(_('Civilité'), choices=civilite_choice,max_length=200,null=True, blank=True)
fonction = models.CharField(max_length=200, null=True, blank=True)
telephone = models.CharField(blank=True, null=True, max_length=16)
adresse = models.TextField()
mobile = models.CharField(blank=True, null=True, max_length=16)
email = models.EmailField(blank=True, null=True)
divers = models.TextField(blank=True, null=True)
service = models.CharField(max_length=300, blank=False, null=False)
def __str__(self):
return self.nom + ' '+self.prenom
class Actions(models.Model):
statut_action_choice=(
('Encours','Encours'),
('En attente','En attente'),
('Terminée','Terminée'),
('Annulé','Annulé')
)
action_date =models.DateTimeField(auto_now_add=True)
action_modification = models.DateTimeField(auto_now=True)
de = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
a = models.ForeignKey(Contacts, on_delete=models.CASCADE, null=False)
cc = models.EmailField(max_length=254,null=True,blank=True)
file = models.FileField(_('Document joint'),upload_to='action/%Y/%m/%d', blank=True)
statut = models.CharField(max_length=30, choices=statut_action_choice, default='Encours')
action = RichTextField(_('Actions'))
history = HistoricalRecords()
views.py
@login_required(login_url='/account/login')
def add_action(request):
if request.method == 'POST':
form = ActionForm(request.POST, request.FILES)
if form.is_valid():
email_to=form.cleaned_data['a']
cc = form.cleaned_data['cc']
action=form.save(commit=False)
action.de = request.user
action.save()
email_subject = 'Vous avez une action à exeducter'
email_from = 'example@mails.com'
email_body = 'Cher vous avez reçu une notification pour action. Veuillez ne pas ' \
'répondre à cette notification.'
email=EmailMessage(email_subject,
email_body,
email_from,
[email_to,],
[cc],
)
email.send(fail_silently=False)
return redirect(reverse('courriers:list_courrier'))
else:
form = ActionForm()
return render(request,
'courriers/actions/add_action.html',
{'form':form})
我的模板
{% extends 'base.html' %}
{% block content %}
{% load crispy_forms_tags %}
<div class="form-group">
<form action="." method="post" enctype="multipart/form-data">
{% csrf_token %}
{{form.media}}
{{form|crispy}}
<button type="submit" class="btn btn-primary"> Enregistrer </button>
</form>
</div>
{% endblock %}
{%extends'base.html%}
{%block content%}
{%load crispy_forms_tags%}
{%csrf_令牌%}
{{form.media}
{{form | crispy}}
登记员
{%endblock%}