title: Django-Edit and update the existing data in database with Form
body: <p>Hello the I need to edit and update the already existing row of data in the database.I guess that their is some problem in views.py. So I am not sure my views.py is right. Please check and tell me if any problem and how to proceed.</p>
  
  <p>Thanks</p>
  
  <p>models.py is :</p>
  
  <pre><code>    class chefequipe(models.Model):
      nom = models.CharField(max_length=200)
      prenom = models.CharField(max_length=200)
      matricule = models.CharField(max_length=200)
      login = models.CharField(max_length=200)
      password = models.CharField(max_length=200)
      statut = models.CharField(max_length=200)
      objects = models.Manager()
       def __str__(self):
          return self.matricule
  </code></pre>
  
  <p>the forms.py :</p>
  
  <pre><code>    class ChefEquipeRegister(forms.Form):
      nom= forms.CharField(required=True , widget=forms.TextInput)
      prenom=forms.CharField(required=True , widget=forms.TextInput)
      matricule=forms.CharField(required=True , widget=forms.TextInput)
      login=forms.CharField(required=True , widget=forms.TextInput)
      password=forms.CharField(required=True , widget=forms.PasswordInput)
      statut=forms.CharField(required=True , widget=forms.TextInput)
  </code></pre>
  
  <p>the view.py</p>
  
  <pre><code>    def updatechef(request , id):
      var=models.chefequipe.objects.filter(id=id)
      form_data = forms.ChefEquipeRegister(request.POST or None )
  
      if form_data.is_valid():
  
  
  
   chefequipe = models.chefequipe()
      chefequipe.nom = form_data.cleaned_data['nom']
      chefequipe.prenom= form_data.cleaned_data['prenom']
      chefequipe.login = form_data.cleaned_data['login']
      chefequipe.password = form_data.cleaned_data['password']
      chefequipe.statut = form_data.cleaned_data['statut']
      chefequipe.matricule = form_data.cleaned_data['matricule']
  
      chefequipe.save()
  
  
  
  context= {
      'var' : var,        
  }
      return render(request , 'administrateur/updatechef.html', context  )
  </code></pre>
  
  <p>the page html</p>
  
  <pre><code>    {% extends 'baseadmin.html' %}
  
  {% block content %}
  
  &lt;form action="" method="post"&gt;
  
  
  
  
  
      &lt;div class="container"&gt;
          &lt;div class="columns is-mobile"&gt;
              &lt;div class="column is-half is-offset-one-quarter"&gt;
  
                  &lt;form action="" method="post"&gt;
                      {%  csrf_token %}
  
                      {% for var in var %}
                      &lt;div class="content"&gt; &lt;h1&gt;  Modifier Information Chef D'équipe : {{var.prenom }} {{ var.nom }}  &lt;/h1&gt;&lt;/div&gt;
                   &lt;label&gt;Nom&lt;/label&gt;  &lt;input id="nom" type="text" name="nom" value="{{ var.nom }}"&gt;
                   &lt;label&gt;Prenom&lt;/label&gt;  &lt;input id="prenom" type="text" name="prenom" value="{{ var.prenom }}"&gt;
                   &lt;label&gt;Matricule&lt;/label&gt;  &lt;input id="matricule" type="text" name="matricule" value="{{ var.matricule }}"&gt;
                   &lt;label&gt;Statut&lt;/label&gt;  &lt;input id="statut" type="text" name="statut" value="{{ var.statut }}"&gt;
                   &lt;label&gt;Login&lt;/label&gt;  &lt;input id="login" type="text" name="login" value="{{ var.login }}"&gt;
                   &lt;label&gt;Password&lt;/label&gt;  &lt;input id="password" type="text" name="password" value="{{ var.password }}"&gt;
                      {% endfor %}
  
  
  
  
                          &lt;/div&gt;
                      &lt;input type="submit" value="Modifier" class="button is-primary"&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  {% endblock %}  
  </code></pre>
  
  <p>i need to update the data exsting in my database</p>