就这样!我想更改图像以供用户在要更改其个人资料图片时输入,但是即使其他信息发生更改也无法使用。
views.py:
@login_required(login_url="")
def personne_form_view(request):
if request.method == 'POST':
form = PersoForm(request.POST, request.FILES,error_class=ParagraphErrorList)
personne = Personne.objects.filter(Q(nom_pre__icontains=request.POST.get('nom_pre')))
if form.is_valid():
if not personne :
form.save(commit=True)
return redirect('manapoitra_client')
else :
messages.warning(request,'Cette personne existe déjà!')
else:
form = PersoForm()
return render(request, 'personneH.html', {'form': form})
是更新人员的视图:
@login_required(login_url="")
def update_client(request, pk):
client = Personne.objects.get(pk=pk)
form = PersoForm(request.POST or None,error_class=ParagraphErrorList, instance=client)
if form.is_valid():
form.save()
return redirect('manapoitra_client')
return render(request, 'editClient.html', {'form': form, 'client': client})
models.py:
class Personne(models.Model):
tof = models.FileField(verbose_name="Photo")
nom_pre = models.CharField(max_length=60, verbose_name="Nom")
choices_sexe = (
('F', 'Femme'),
('H', 'Homme')
)
sexe = models.CharField(max_length=1,choices=choices_sexe)
adresse = models.CharField(max_length=70, verbose_name="Adresse")
telephone = models.CharField(max_length=10, verbose_name="Télèphone")
email = models.EmailField(verbose_name="Courriel")
agence = models.ForeignKey(Agence, verbose_name="Agence", on_delete=models.CASCADE)
service = models.ForeignKey(Service, verbose_name="Service", on_delete=models.CASCADE)
date = models.DateTimeField(auto_now_add=True, verbose_name="Date de création")
def __str__(self):
return self.nom_pre
et dans mon模板:
{% extends 'base.html' %}
{% block content %}
<div class="centrer">
<form method="POST">
{% csrf_token %}
<table>
{{ form.as_table }}
<tr>
<td></td>
<td><button class="btn btn-info formbut">Sauvegarder</button></td>
</tr>
</table>
</form>
</div>
{% endblock %}
先谢谢您