I've created a form that allows a user to edit a datum in a model. However, when a user performs an edit, django adds that value as a new datum rather than editing the existing datum in the database. Any idea what's wrong?
#Model ################################################################# class Recipe(models.Model): recipe_name = models.CharField(max_length=100, verbose_name='Recipe Name') ingrediants = models.TextField(blank=True, verbose_name='Ingrediants') instructions = models.TextField(blank=True, verbose_name='Instructions') external_url = models.URLField(blank=True, verbose_name='External URL') cuisine = models.ForeignKey(Cuisine) course = models.ForeignKey(Course) image = models.ImageField(blank=True, upload_to='img2/') thumbnail = models.ImageField(blank=True, upload_to='img/thumbs/') one_liner = models.CharField(max_length=100, blank=True, verbose_name='Comments') tag_list = models.ManyToManyField(Tag, blank=True, verbose_name='Tags') user = models.ForeignKey(User) def __unicode__(self): return self.recipe_name class Admin: pass #ModelForm #################################################### class RecipeForm(ModelForm): class Meta: model = Recipe exclude = ('user','thumbnail','tag_list') # View that creates form #################################################### def testForm(request, recipe_id): r = Recipe.objects.get(pk=recipe_id) f = RecipeForm(instance=r) return render_to_response('chef/test-form.html', {'form':f}) # View that processes form ################################################## def editConfirm(request): f = RecipeForm(request.POST, request.FILES) if not f.errors: modified_recipe = f.save(commit=False) modified_recipe.user = User.objects.get(id=1) #placeholder until I add users; necessary for FK relation modified_recipe.save() return render_to_response('chef/edit-confirm.html', {'recipe': modified_recipe}) else: msg = 'Form not valid' return render_to_response('chef/error.html', {'msg':msg}) # Template w/Form ###### <html><head> <title>Add New Recipe</title> <link rel="stylesheet" type="text/css" href="/media/style/style.css" / > </head><body> <table> <form enctype="multipart/form-data" method="post" action="/ chef/edit-confirm/" method="post"> {{ form.as_table }} <tr> <td><input type="submit" value="Save Changes"></td> <td><input type="submit" value="Cancel"></td> </tr> </form></table> </body> </html> Thanks all! ~John --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---