Here are what my models look like
======================================================
# Standard Header for application models
from django.db import models
from django.forms import ModelForm
#imported for use of "USPhoneNumberField" and "USStateField"
from django.contrib.localflavor.us.models import *
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
# employer = models.CharField(max_length=100)
# position = models.CharField(max_length=50)
email = models.EmailField()
class Address(models.Model):
line_1 = models.CharField(max_length=60)
# line_2 = models.CharField(max_length=60,blank=True,null=True)
city = models.CharField(max_length=30)
state = USStateField()
zip = models.CharField(max_length=10)
# newsletter = models.BooleanField()
# mail_opt_out = models.BooleanField()
# phone_primary = models.CharField(max_length=12)
# phone_secondary = models.CharField
(max_length=12,blank=True,null=True)
# phone_primary_type = models.ForeignKey(contact_phone_types,
related_name='primary_set',blank=True,null=True)
# phone_secondary_type = models.ForeignKey(contact_phone_types,
related_name='secondary_set',blank=True,null=True)
# email = models.EmailField(max_length=30,blank=True)
# preferred = models.ForeignKey
(contact_preferred,blank=True,null=True)
class AddressForm(ModelForm):
class Meta:
model = Address
class PersonForm(ModelForm):
class Meta:
model = Person
# Create your models here.
class Lead(models.Model):
# a lead is a person
person = models.ForeignKey(Person);
# a lead has address information
address = models.ForeignKey(Address);
# definitions
def __unicode__(self):
return '%s %s' % (self.first_name, self.last_name)
def full_name(self):
return '%s %s' % (self.first_name, self.last_name)
def get_absolute_url(self):
return "/contacts/%i/" % self.id
#--------------------------------------------------
class Admin:
pass
class LeadForm(ModelForm):
class Meta:
model = Lead
==============================================================
Here is my views.py of the app "leads"
==============================================================
from django.db.models import Q
from django.shortcuts import render_to_response
from base.leads.models import *
from django.forms.models import modelformset_factory
from django.forms.models import inlineformset_factory
def manage_lead (request):
lead_id=1
person = Person.objects.get(pk=lead_id)
address = Address.objects.get(pk=lead_id)
LeadFormSet = inlineformset_factory(Lead, Address, Person)
# If data was POSTed we're adding new lead
if request.method == 'POST':
formset = LeadFormSet(request.POST, request.FILES,
instance=person, instance=address)
if formset.is_valid():
# Form processing
formset.save()
# otherwise we're adding a form to be filled out
else:
formset = LeadFormSet()
return render_to_response('leads/manage.html', {
"formset": formset,
})
==========================================
I know my "manage_lead" def isn't good, I'm still trying to find out
how to do this.
Basically what I want to do is get it so that I pass one formset to
the render that is composed of both Person and Address forms.
Thanks everyone! Also if there is a resource I can use to find answers
to this myself?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---