Hi all,
I have been trying to achieve following scenario:
1. I have a model named ContactRow
class ContactRow(models.Model):
  """Emergency contact row model """
  card = models.ForeignKey(ContactCard, related_name='data') #
ContactCard is another model.

  name = models.CharField(max_length=22)
  phone1 = models.CharField(max_length=20, blank=True)
  relation=models.CharField(max_length=30, blank=True)
  location=models.CharField(max_length=30, blank=True)

2.Form and  Formset are defined as

class ContactRowForm(forms.ModelForm):
  """Emergency contact row form """
  class Meta:
    model = ContactRow
    exclude = ('card')

ContactRowFormSet = inlineformset_factory(ContactCard, ContactRow,
extra=0, can_delete=True)

3. In my template, I display the formset and want to enable the user
to delete an individual row in the formset.
I have provided a checkbox as below:

      {% for data in formset.forms %}
      <tr>
        <td>{{ data.id }}</td>
        <td><input type="checkbox" name="deleteRow" value=
{{ forloop.counter0 }}/></td>
        <td>{{ data.name }}</td>
        <td>{{ data.phone1 }}</td>
        <td>{{ data.relation }}</td>
        <td>{{ data.location }}</td>
      </tr>
      {% endfor %}

I extract the value of checkbox in the view and using that I want to
delete the DB instance. I provided, {{ forloop.counter0 }} as the
value but it is not a solution as we need some primary key to be the
value of checkbox. Asigning {{ data.id }} does not work as template
tries to translate it into an input field.

Can anyone give me any ideas to accomplish the deletion of individual
rows i formset.

Thanks in advance,
Sonal.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to