Sunday, June 20, 2010

Help with Formset (I think it is formset I need)

Hello:

I am trying to create a form with a check box list for Tags associated
with an Appointment.

Form:
Please list tags for this Appoingmen _ Work
_ School
_ Other

I need to design this so users can add additional tags later.

Appoitnemts and Tags are M2M related:

class Appointment(models.Model):
name = models.CharField(max_length=64)

class Tag(models.Model):
name = models.CharField(max_length=64, unique=True)
appointments = models.ManyToManyField(Appointment)

My Forms Class:

class TagForm(forms.Model.Form):
tags = forms.ModelMultipleChoiceField(queryset=Tag.objects.all(),
widget=forms.CheckboxSelectMultiple() )

class Meta:
model = Tag

In my view I have also tried:

TagFormSet = modelformset_factory(Tag, form=TagForm)
tag_form = Tag = TagFormSet(query =
Tag.object.all())

This looks right when the form is displayed, exepct the form is
duplicated once for each Tag in my Db, and clearly this is not pulling
or saving to the Db correctly.

I have looked through the Django documentation, but cannot figure out
how to implement the formset correctly (I think it is a formset I need
here).

Any help would be greatly appreciated.

Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment