Created
September 9, 2008 06:29
-
-
Save trey/9621 to your computer and use it in GitHub Desktop.
Doing multiple things on a single view / page (form and a list).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import HttpResponseRedirect | |
from django.views.generic import list_detail | |
from myapp.models import * | |
from myapp.forms import EntryForm | |
def entry_list(request, page=0): | |
if request.POST: | |
form = EntryForm(data=request.POST) | |
if form.is_valid(): | |
form.save() | |
return HttpResponseRedirect('/something/') | |
else: | |
return render_to_response('entry_form.html', {'form': form}) | |
else: | |
return list_detail.object_list( | |
request, | |
queryset = Entry.objects.all(), | |
template_object_name = 'entry', | |
template_name = 'read.html', | |
paginate_by = 10, | |
page = page, | |
extra_context = {'form': EntryForm} | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment