Thanks man, but I am still suffering from another thing,
look at this code:
@csrf_exempt
@login_required
def update_book(request):
dontvalidate = request.POST['dontvalidate']
book_id = int(request.POST['book_id'])
book = get_object_or_404(Book, id = book_id)
if dontvalidate == 'yes':
bookform = BookForm(instance = book)
else:
booknoteform = BookForm(request.POST, request.Files)
if bookform.is_valid():
bookform.save()
return render_to_response(
'books/update_book.html',
{
'bookform':bookform,
'dontvalidate': dontvalidate,
'is_authenticated' : request.user.is_authenticated(),
},
context_instance = RequestContext(request)
)
Once the update code is printed on the screen, all old fields are
there except the one for the FileField.
I coundn't fill out the file data filed with old file saved when the
form was created.
The Book model is like
class Book(models.Model):
user = models.ForeignKey(User)
title = models.CharField(max_length = 100)
author = models.CharField(max_length = 100)
publisher = models.CharField(max_length = 100)
publication_date = models.DateField()
front_page = models.FileField(upload_to='books')
def __unicode__(self):
return self.title
On Jan 18, 10:31 am, Derek <[email protected]> wrote:
> First read and
> understand:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>
> Then:
> 1.http://stackoverflow.com/questions/1645444/django-modelform-accessing...
> 2.http://neverfear.org/blog/view/123/Auto_Generate_Forms_With_Django_s_...
>
> On Jan 16, 8:43 am, Benchouia Ahmed Abdelhakim <[email protected]>
> wrote:
>
> > Hello there,
>
> > I am new to django developement model. If someone know
> > 1- how to access to the ModelForm fields instance in the view?
> > 2- I am trying to developpe a website that contains many forms, is
> > there a way to make the same template (new and update) for a given
> > model.Models class
>
> > thanks,
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.