title: django view to display the model form in a template
body: <p>I've created a model form.I'd like to display it on webpage and push the form data into the database: below is model and the view. Here the topic_id and the command_id should be auto-generated by the db. Please let me know if the view I've created is correct.</p>
  
  <p>Thanks,
  Arun</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>from django.db import models
  # Create your models here.
  from django.forms import ModelForm
  
  class Topics(models.Model):
      topic_id = models.AutoField(primary_key=True)
      topic_name = models.CharField(max_length=200)
      def _unicode_(self):
          return self.name
  
  class Command(models.Model):
      command_id = models.AutoField(primary_key=True)
      title = models.CharField(max_length=200)
      command = models.CharField(max_length=200)
      description=models.CharField(max_length=200)
      topic_under=models.ForeignKey(Topics)
      def _unicode_(self):
          return self.name
  
  class TopicsForm(ModelForm):
      class Meta:
          model = Topics
  
  class CommandForm(ModelForm):
      class Meta:
          model = Command
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code># Create your views here.
  from command.models import Command
  from command.models import CommandForm
  from django.shortcuts import render_to_response, get_object_or_404
  from django.template import RequestContext
  from django.core.context_processors import csrf
  
  def submitform(request):
      if request.method == "POST":
          form = CommandForm()
          if form.is_valid():
             form.save()
             return render(request, 'newcommand.html')
      else:
          form = CommandForm()
          return render(request, 'inputtest.html', {'form': form})
  </code></pre>