Opened 16 years ago
Closed 16 years ago
#10544 closed (invalid)
Saving ModelForm to update exisitng record generates No {model} matches the given query. — at Version 1
Reported by: | mcwong644 | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
#models.py class Publisher(models.Model): name = models.CharField(max_length=30) address = models.CharField(max_length=50) city = models.CharField(max_length=60) state_province = models.CharField(max_length=30) country = models.CharField(max_length=50) website = models.URLField() def __unicode__(self): return self.name class Meta: ordering = ["name"] class Author(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=40) email = models.EmailField(blank=True, verbose_name='e-mail') objects = models.Manager() sel_objects=AuthorManager() def __unicode__(self): return self.first_name+' '+ self.last_name class Book(models.Model): title = models.CharField(max_length=100) authors = models.ManyToManyField(Author) publisher = models.ForeignKey(Publisher) publication_date = models.DateField(blank=True, null=True) num_pages = models.IntegerField(blank=True, null=True) objects = models.Manager() bookobjects = BookManager() wong = WongAuthor() class BookForm(ModelForm): class Meta: model = Book #view.py def authorcontactupd(request,id): if request.method == 'POST': a=Author.objects.get(pk=int(id)) form = AuthorForm(request.POST, instance=a) if form.is_valid(): form.save() return HttpResponseRedirect('/contact/created') else: a=Author.objects.get(pk=int(id)) form = AuthorForm(instance=a) return render_to_response('author_form.html', {'form': form})
Produces this error
Page not found (404) Request Method: POST Request URL: http://127.0.0.1:8000/books/bookupd/ No Publisher matches the given query. You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Change History (1)
comment:1 by , 16 years ago
Description: | modified (diff) |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
This looks like a problem in your code, rather than Django. Please post some details to the mailing list to get help with this.
I'll note that the error is reporting a problem about the
Publisher
model, which is not going to be used byAuthorForm
at all. So you should start out by checking you are debugging the right problem.(fixed description)