On 1/12/07, Felix Ingram <[EMAIL PROTECTED]> wrote: > > Hello all, > > I've been playing around with the newforms library and I'd like to > check that I'm on the right track. > > I've got a fairly complicated model that has a few foreign keys and > m2m fields. One of the m2m fields references a table with ~130,000 > rows so the usual select boxes aren't that usable. I've created a form > which simplifies the entry but I would like to check the preferred way > of doing certain things. > > 1. Additional validation - One field is a RegexField but I would like > to add extra validation. At the moment I've subclassed it and added my > own 'clean' method.
You can either override clean (remember to call the super.clean) on the field, or implement clean_FIELD on the form > > 2. Saving the model - I've implemented a save method in the form which > will return an instance of the model in a similar fashion to > form_for_model. Is this good practice or should I create the instance > in my view and populate it from the form? I do the same thing since I reuse the form in multiple views > > 3. Binding data - I'd like the form to handle editing of an instance. > I could construct a dictionary of values and pass it to the form as > per the docs but I'd like to just pass a model instance and have the > form sort things out. Is this advisable? If so then does anyone have > any pointers about what methods I need to implement? the easiest way how to do this is in __init__ of the form create the dictionary from the model and use it when calling super.__init__ > > Thanks in advance for any pointers. > > Felix > > P.S. Are there any thoughts about form inheritance? I'd like to be > able to create a form base on another but with some more fields. At > the moment this doesn't seem to work as expected... it works but only for dynamic fields added via self.fields['name'] = forms.Field(...) I use it with success > > > > -- Honza Král E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---