See also: Heapify

Go back to post Create new comment

RSS Be notified of new comments on this post with the RSS feed for this post.

#
 ip = forms.IPAddressField )

You should correct this line.

#

Thanks a lot! Examples always help.. :)

#

This works! Thanks for sharing.

#

model using ModelForm: models.py

from django.db import models from django.forms import ModelForm

class customers(models.Model): name = models.CharField(max_length=50) custAdd = models.TextField()

class Meta:
    db_table = 'tb_amit_test'
    ordering = ['-name']
    verbose_name_plural = 'customers'
 
def __unicode__(self):
    return self.name
 
@models.permalink
def get_absolute_url(self):
    return ('customers_customers', (), { 'customers_name': self.name })

class customerForm(ModelForm): class Meta: model=customers

View:views.py

from django.shortcuts import render_to_response from mtcc_customer_db import customers from mtcc_customer_db import customerForm from django.template import RequestContext

def adddata(request): if request.method == 'POST': f=custform(request.POST) if f.is_valid():
newcust=f.save(commit=False) newcust.save() return HttpResponseRedirect('/') return render_to_response('index.html', context_instance=RequestContext(request))

URLs:

from django.conf.urls import patterns, include, url from mtcc_customer_db import settings from django.contrib import admin admin.autodiscover()

urlpatterns = patterns('', # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)),)

urlpatterns +=patterns('mtcc_customer_db.customers.views', (r'^customers/$', 'adddata'),)

Template: customer.html

{% extends "base.html" %}

{% block site_wrapper %}

<

div id="main"> {% include "tags/navigation.html" %}

    <a href="#content" class="skip_link">Skip to main content</a>
    <form action="." method="post">
    <input type="text" name="name" id="name" value="{{name}}">
     <input type="text" name="custAdd" id="custAdd" value="{{custAdd}}">
     <input type="submit" value="Submit">
    </form>.........

{% endblock %}

I am getting the error in the browser:

Request Method: GET Request URL: http://127.0.0.1:8000/customers/ Django Version: 1.4.3 Exception Type: ImportError Exception Value:

cannot import name customerForm

Where am i going wrong?? Please help

Go back to post

Create a new comment

Go to the top

You can use a restricted version of markdown formatting here. You can use the toolbar above the text field to make this more painless. For more information about markdown please refer to the markdown cheatsheet.

For post: Auto Generate Forms With Django's ModelForm
Your name:
Your email (optional):
Your website (optional):
 
 
 

A preview of your comment:

RSS
Powered by Debian, Guinness, and excessive quantities of caffeine and sugar.