This is a simple demonstration on how to submit data via a form into a database. It provides the minimal steps to be performed to accomplish this:
Create the template which is the html returned to the browser.
models.py: ::
from django.db import models
CHOICES = (1:'small', 2:'medium', 3:'huge')
class SimpleColumn(models.Model): column = models.CharFiedl(max_length=255, choices=CHOICES)
forms.py: ::
from django import forms
class Simple ColumnForm(forms.ModelForm): class Meta: model = SimpleColumn
views.py: ::
from django.shortcuts import render from forms import SimpleColumnForm
def view_column(request): if request.method = "POST": form = SimpleColumnForm(request.POST) if form.is_valid(): form.save() else: form = SimpleColumnForm() return render(request, 'view_column.html', {'form': form})
view.html: ::
Comment on This Data Unit