On Sat, 26 Jan 2013 11:39:20 -0800 (PST) sephii <[email protected]> wrote: > Hey there, > > I'm trying to create a form with a "static" part (a "title" field, a > "date" field) and a variable part (these are "artist names", so > that's a single field that can be repeated multiple times, with a > minimum of 1). I first thought about the MultiValueField but it > requires several fields, and in my case I only want to use 1 field, > just like an inline with one field in the Django admin. I then tried > to go with a Formset, but I wasn't able to set it as mandatory (even > if the field is marked as mandatory, if it's left blank it's just > like the form is not filled so the validation always passes). Here's > the code I tried for the formset part:
When one entry in one table/model has several assorted entries of an independent type, thats called a 1-to-n-relation. Or a OneToManyField in django. So essentially when you have a list of CDs, they all have album, title and stuff. But then you have a list of artists and each of these entries belongs to one CD while one CD can have several artist entries. OneToManyField from the artist to the CD. But one artist can be on several CDs. So actually you want to look at the ManyToManyField, because one artist can be on several CDs and several artists can be on one CD. Thats an n-to-m relation. Once you get these relations right, the django forms do the rest for you. Maybe that helps, Arnold
signature.asc
Description: PGP signature

