I found a solution off of stack overflow. I had to bind an instance to the form when editing. So I changed the following line:
form = ProjectForm(request.POST, instance=project) It seems to work and is in testing. On Oct 7, 5:40 pm, Streamweaver <streamwea...@gmail.com> wrote: > Some more information. The view method to save the item is as follows: > > def update_project(request, slug): > '''Method for editing already existing projects.''' > > project = get_object_or_404(Project, slug=slug) > if request.method == 'POST': # If form was submitted run it > through. > form = ProjectForm(request.POST) > if form.is_valid(): > form_instance = form.save(commit=False) > form_instance.id = project.id > form_instance.created_on = project.created_on > form_instance.save() > return HttpResponseRedirect(reverse('view-project', args= > [slug])) > else: > form = ProjectForm(instance=project) > > return render_with_context(request, 'project/projectedit.xhtml', { > 'form': form, > 'action': reverse('update-project', > args=[slug]), > 'button': 'Update Project', > 'title': 'Editing Project' > }) > > On Oct 7, 5:24 pm, Streamweaver <streamwea...@gmail.com> wrote: > > > The title field in my model is set to unique and when I use a form to > > edit this I get an error that an item with this value already exists. > > > As I understand it this is because ModelForm throws an error when I > > call form.is_valid() and all information I can find tells me to > > override the clean method in the form however it seems like this > > requires me to reimplement the entire validation code again? > > > Is there an easier way to deal with unique text fields in form > > validation for existing data? > > > Thanks in advance for any help. > > --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---