Created
August 25, 2015 22:28
Revisions
-
git2samus created this gist
Aug 25, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ from django import forms from students.models import Student, Longlist class StudentForm(forms.ModelForm): class Meta: model = Student fields= ('name_text',) class InputForm(forms.ModelForm): class Meta: model = Longlist fields = ('text_input',) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ <h1>Enter in a BIG list of names and email addresses of students.</h1> {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} <form id="InputForm" method="post" action="/students/textInput/"> {% csrf_token %} {% for hidden in form.hidden_fields %} {{ hidden }} {% endfor %} {% for field in form.visible_fields %} {{ field.errors }} {{ field.help_text }} {{ field }} {% endfor %} <input type="submit" value="Create Students" /> </form> This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ def textInput(request): # A HTTP POST? if request.method == 'POST': form = InputForm(request.POST) # Have we been provided a valid form? if form.is_valid(): # Save the new student list to the database. form.save(commit=True) # Parse the textInput so the name is added to the db l = "" l = Longlist.objects.order_by('-id')[:1] # get the latest entry for Longlist print l # Now call the index() view. # The user will be shown the homepage. return entry(request) else: # The supplied form contained errors print form.errors else: # If the request was not a POST, display the form to enter the details. form = InputForm() # Bad form (or form details), no form supplied... # Render the form with error messages (if any) return render(request, 'students/textInput.html', {'form': form})