Hello, I am studying Django, and I met this problem: "Missing id in QueryDict in a multi Dict error". I try to solve this by many ways, including importing the id with 'idzz' into the form built by form.as_table, but at submit time the system sees no id. How can I inject the current id before a save(). I scanned many FAQ's and tutorials, Trying by the book, but still the same error. My create works, the edit part works but can't save !! What am i missing ?? Thanks for any help.
This is my view:
@login_required def modifier(request,id): idz = request.GET.getitem('id') aModifier = get_object_or_404(artisan,pk=request.GET['id']) form = PrincipaleForme(instance = aModifier)
if request.method == 'POST':
if form.is_valid():
form = PrincipaleForme(request.POST)
form.save()
return HttpResponseRedirect('/')
else:
form = PrincipaleForme(instance = aModifier)
return render_to_response('modifier.html',{'form' : form,'idzz':aModifier.id})
The Model:
class artisan(models.Model):
nom = models.CharField(max_length=100, unique=False)
prenom = models.CharField(max_length=100, unique=False)
qualite = models.CharField(max_length=100, unique=False)
adresse1 = models.CharField(max_length=100, unique=False)
adresse2 = models.CharField(max_length=100, unique=False)
commune = models.CharField(max_length=100, unique=False)
codepostal = models.CharField(max_length=100, unique=False)
artisanat = models.TextField(blank=True)
creation = models.DateField(auto_now_add = True)
inscrit = models.BooleanField(default = True)
photoA = models.CharField(max_length=100, unique=False)
photoB = models.CharField(max_length=100, unique=False)
photoC = models.CharField(max_length=100, unique=False)
photoD = models.CharField(max_length=100, unique=False)
photoE = models.CharField(max_length=100, unique=False)
#imageArtisans = models.ImageField(blank = True, upload_to = 'imgArtisans') #Ajouter des photos dans notre propre API
def __unicode__(self):
return self.nom
The Template:
{%block content%}
Modifier Artisan Num: {{id}}
<table>
{{form.as_table}}
</table>
<p><input type="submit" name="submit" value="Enregistrer"></p>
</form>
<a href = "/" ><div id ="unNom">RETOUR</div></a>
{%endblock%}
Part of the URLS:
(r'^creer/$', 'regional.cetteEtape.views.creer'),
(r'^modifier/(.*)$', 'regional.cetteEtape.views.modifier'),