Skip to content

Instantly share code, notes, and snippets.

@eclecticmiraclecat
Created November 4, 2020 15:00
Show Gist options
  • Save eclecticmiraclecat/07513ed142e4e6196ba8c510f67d266e to your computer and use it in GitHub Desktop.
Save eclecticmiraclecat/07513ed142e4e6196ba8c510f67d266e to your computer and use it in GitHub Desktop.
# forms.py
from django import forms
from .models import Employee

class UserRegistrationForm(forms.ModelForm):
  class Meta:
    model= Employee
    fields = '__all__'
# views.py
from .forms import UserRegistrationForm

# Create your views here.
def display(request):
  form = UserRegistrationForm()
  if request.method=='POST':
    form = UserRegistrationForm(request.POST)
    if form.is_valid():
      form.save()
    return HttpResponseRedirect(reverse('n_onsubmit'))
  return render(request, 'firstApp/index.html', {'form': form})

def onsubmit(request):
  form = UserRegistrationForm()
  return render(request, 'firstApp/submit.html', {'form': form}

notes

  • class Meta tells which model to use
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment