Here's what my models.py
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
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 LeadForm(ModelForm):
class Meta:
model = Lead
class Admin:
pass
==================================================
views.py
==================================================
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,
})
================================
What I have clealry won't work, but I'm wondering how to handle this
situation.
What I want is one formset that has the two ForeignKey's that are in
Lead.
Thanks so much.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---