python - Django - Getting POST data from list within a list in a form -
trying figure out elegant way accurately post data form in django input fields dynamically created user.
i haven't quite coded i'll try describe sufficient detail:
the form follows below models.
class address(models.model): title = models.charfield(max_length=200) instructions = models.textfield() date_time_added = models.datetimefield(auto_now=true, null=true, blank=true) class contact(models.model): address = models.manytomanyfield(stop, through='address_contact') first_name = models.charfield(max_length=100) last_name = models.charfield(max_length=100) phone_num = models.charfield(max_length=20, default='') email = models.charfield(max_length=50, default='') company = models.charfield(max_length=30, default='') date_time_added = models.datetimefield(auto_now=true, null=true, blank=true) class address_contact(models.model): address = models.foreignkey(address, on_delete=models.cascade) contact = models.foreignkey(contact, on_delete=models.cascade) date_time_added = models.datetimefield(auto_now=true, null=true, blank=true)
in user interface adding address , associated contacts, user can click button create more contact entries on same page (accomplished via jquery). initial presentation of form includes relevant fields contact, clicking button 1 or more times, user can add multiple contacts same address.
i know how use getlist() on request.post data.
now problem:
for each contact, it's possible have multiple phone numbers. again achieved on front end via jquery. how can multiple phone numbers each contact when there arbitrary number of contacts , contact numbers each? there way access contents of list within list in kind of ordered way?
for instance, following possible contact entry address:
contact name: john johnson
phone number: 828 282 2999
phone number: 399 399 3999
contact name: steve murphy
phone number: 399 399 3333
contact name: mary west
phone number: 399 399 3000
phone number: 299 392 2003
if requirement maintain multiple values.
you should try foreign key relationship.
take @ this.
Comments
Post a Comment