I am developing an app which consists of multiple models. In my 2nd model in model.py it consist of 2-3 col. of char field but in my template when I am using this {{ form.billing_add }} then it doesn’t show any text input in browser
my model.py file is as
from django.db import models
from django.contrib.auth.models import User
class Customer(models.Model):
user =models.OneToOneField(User)
birthday =models.DateField()
website =models.CharField(max_length=50)
store =models.CharField(max_length=50)
welcomemail =models.CharField(max_length=50)
def __unicode__(self):
return self.user
class Customer_check_attributes(models.Model):
customer = models.ForeignKey(Customer)
billing_add =models.CharField(max_length=50)
shipping_add =models.CharField(max_length=50)
payment_method =models.CharField(max_length=50)
shipping_method =models.CharField(max_length=50)
reward_points =models.CharField(max_length=50)
and my form.py file as
from django import forms
from django.contrib.auth.models import User
from django.forms import ModelForm
from customer_reg.models import Customer,Customer_check_attributes
class Registration_Form(ModelForm):
first_name = forms.CharField(label=(u'First Name'))
last_name = forms.CharField(label=(u'Last Name'))
username = forms.CharField(label=(u'User Name'))
email = forms.EmailField(label=(u'Email Address'))
password = forms.CharField(label=(u'Password'), widget=forms.PasswordInput(render_value=False))
class Meta:
model=Customer
exclude=('user',)
It seems that you want to have a html form which has attributes from multiple models.
So the way would be to create separate form for each model but show it on one page through one view and template and process it in the same.
Here is example
forms
view:
Sample add_customer_template.html
Note: this is a guideline code. There is scope for improvement to handle errors and better logic.