On Jul 16, 2009, at 5:16 AM, Viacheslav Chumushuk wrote:
> <snip>
> class Book(models.Model):
>    author = models.ForeignKey(Author)
>    title = models.CharField(max_length=100)
>
> All that I need is edit some book by primary key.
<snip>

Just make a forms.ModelForm for your Book model. The class Meta will  
contain 'model = Book.' You don't need any of that inline stuff to  
edit a single instance.

Briefly (assuming your ModelForm is named BookForm):

In your view, you will make an instance of your ModelForm:

book_form = BookForm()

Then do the typical render_to_response bit.

You will also have an if request.POST in your view. If that's hit,  
then you will declare your form like this:

book_form = BookForm(request.POST) #if you're not doing a  
request.POST.copy(), which you probably should.

Then: if book_form.is_valid(), you save it. If not, you let it fall  
out of that if statement into your render_to_response part.

Make sure that if the form doesn't validate, you're not doing the  
"bare" book_form = BookForm() and overwriting your bound version. The  
bare version could be above the if, or in an else clause.

Shawn
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to