I have a 2 forms. One to add a new author and then another form for
Articles which has a drop down list to reference the authors. The
behavior I am seeing is that when I add a new author and then go to
the New Article form which references the author it does not display
the new record. Also, I put in some print statements in the New
Article form class and those statements are only executed when I go to
my home page.
Here are my code snippets
def welcome(request):
print 'in welcome'
if request.GET:
if request.GET.has_key( 'newarticle'):
print 'going to new article'
return HttpResponseRedirect( '/melsite/newarticle')
if request.GET.has_key( 'newauthor'):
print 'going to new author'
return HttpResponseRedirect( '/melsite/newauthor')
else:
print 'retrieving articles'
articles = Article.objects.filter
(type_index__type='Poem').order_by('title')
return render_to_response('stories/welcome.html', {'title':
'Poems', 'articles': articles})
def newarticle( request):
print 'in new article request'
from storyforms import NewArticle
if request.method == 'POST':
print 'in new article post'
new_data = request.POST.copy()
articleform = NewArticle(new_data)
if form.is_valid():
form.save( new_data)
articles = Article.objects.filter
(type_index__type='Poem').order_by('title')
return render_to_response('stories/welcome.html',
{'title': 'Poems', 'articles': articles})
else:
print 'in setting up new article'
#from storyforms import NewArticle
articleform = NewArticle()
print 'after setting up new article'
print 'rendering article'
return render_to_response('stories/add_story.html', {'form':
articleform})
class NewArticle( forms.Form):
articletypelist=[]
authorlist = []
print 'in new article class'
articletypes = ArticleType.objects.all().order_by( 'type')
articletypelist.append( selecttuple)
for articletype in articletypes:
choicestr = "choice%s" % str( articletype.id)
typetuple = choicestr, articletype.type
articletypelist.append( typetuple)
authors = Author.objects.all().order_by( 'last_name')
print 'authors in new article are ', authors
authorlist.append( selecttuple)
for author in authors:
choicestr = "choice%s" % str( author.id)
authorname = author.first_name + ' ' + author.last_name
authortuple = choicestr, authorname
authorlist.append( authortuple)
ArticleType = forms.ChoiceField( choices=articletypelist)
Author = forms.ChoiceField( choices=authorlist)
Title = forms.CharField()
Content = forms.CharField( widget=forms.Textarea)
print 'end of new article def'
Thanks,
Jeff
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---