-
-
Save geoffa/247675 to your computer and use it in GitHub Desktop.
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 import forms | |
from myapp.models import Mymodel | |
class MyForm(forms.ModelForm): | |
class Meta: | |
model=Mymodel | |
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.shortcuts import render_to_response | |
from myapp.forms import MyForm | |
def my_view(request): | |
""" | |
Documentation for my view. | |
""" | |
if request.POST: | |
form = MyForm(data=request.POST) | |
if form.is_valid(): | |
form.save() | |
return HttpResponseRedirect('/') | |
# else: | |
# Errors and validation message taken care of for you. Neat. | |
else: | |
form = MyForm() | |
return render_to_response('my_template.html', {'form': form}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment