my Blog models.py is
class Blog(models.Model):
title = models.CharField('Title', max_length=200)
text = models.TextField('Text', max_length=2048)
date = models.DateTimeField('Last Modified')
def __unicode__(self):
return '%s' % (self.title)
and in my views.py I'm trying to convert models field to form field and then appending data, in the following views.py code I'll get a page where it asks for title and text only...
class BlogForm(ModelForm):
class Meta:
model = Blog
fields=('title', 'text')
def add_blog(request, pID='0'):
bf = BlogForm()
message = 'Unknown Request'
p = get_object_or_404(Person, pk=pID)
if request.method == 'GET':
message = 'Add Blog for %s ' % p.name
if request.method == 'POST':
if request.POST['submit'] == 'Add':
SaveForm = BlogForm(instance=p)
bf = BlogForm(request.POST.copy())
postDict = request.POST.copy()
postDict['date'] = datetime.datetime.now()
save_bf = SaveForm(postDict)
if save_bf.is_valid():
try:
bObj = save_bf.save()
p.blogs.add(bObj)
p.save()
message = 'Blog added to %s.' % p.name
except:
message = 'Database Error.'
else:
message = 'Invalid data in Form.'
return render_to_response(
'people/add_blog_form.html',{'bForm': bf,'message':message})
"But after subitting data I'll get the following error"
TypeError at /Blog/AddBlogForm/1/
'BlogForm' object is not callable
Request Method: POST Django Version: 1.4.1 Exception Type: TypeError Exception Value: 'BlogForm' object is not callable
Getting error in the line "save_bf = SaveForm(postDict)"