Re: FormGen Script

2007-01-04 Thread Felix Ingram


On 04/01/07, Adrian Holovaty <[EMAIL PROTECTED]> wrote:

On 1/4/07, Felix Ingram <[EMAIL PROTECTED]> wrote:
> ScaffoldScript is dead; long live FormGen!
> Using this script: http://code.djangoproject.com/wiki/FormGenScript
> in this manner: python formGen.py -a MyApp -m Category

Hey Felix,

Have you seen django.newforms.form_for_model and form_for_fields?
They're intended to do these things in a dynamic way. See the unit
tests in tests/modeltests/model_forms/models.py for examples.


Hi Adrian,

Thanks for the pointer. I haven't seen form_for_fields; I look forward
to the unittests. One 'problem' I've found with form_for_model (and
the auto manipulators back in the day) is that it's tricky to tweak a
single field if necessary.

My longstanding problem has been that I need to edit a many2many field
but the other table will contain over 100,000 rows. This takes a while
to load into the select field and isn't really that helpful. I've been
using a text field and chopping up the input to get the foreign
values. It's quite tricky to swap out the select field and add the
validators (especially in a maintainable way).

Therefore I whipped up the script to spew out the forms which I then
tweak as appropriate (I hope Fred doesn't look at it; he'll take my
license away for sure).

I'll be cheeky and ask my inheritance question again if that's okay:
is it possible for a Form to inherit from another. I'd like a form for
admin users which adds extra fields. Is something like this possible:

class JoeUserForm(forms.Form):
   name = forms.CharField()

class AdminForm(JoeUserForm):
   give_pay_rise = forms.BooleanField()

Thanks again for the reply,

Felix

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: FormGen Script

2007-01-04 Thread Adrian Holovaty


On 1/4/07, Felix Ingram <[EMAIL PROTECTED]> wrote:

ScaffoldScript is dead; long live FormGen!

Using this script: http://code.djangoproject.com/wiki/FormGenScript

in this manner: python formGen.py -a MyApp -m Category


Hey Felix,

Have you seen django.newforms.form_for_model and form_for_fields?
They're intended to do these things in a dynamic way. See the unit
tests in tests/modeltests/model_forms/models.py for examples.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



FormGen Script

2007-01-04 Thread Felix Ingram


ScaffoldScript is dead; long live FormGen!

Using this script: http://code.djangoproject.com/wiki/FormGenScript

in this manner: python formGen.py -a MyApp -m Category

will turn this model:

class Category(models.Model):
   category = models.CharField(maxlength=50, unique=True)
   createdOn = models.DateField(auto_now_add=True)
   modifiedOn = models.DateField(auto_now=True)
   test = models.ManyToManyField(auth.User, verbose_name='This is a
test field', related_name='test')
   test2 = models.OneToOneField(auth.User, verbose_name='test2',
related_name='test2')

Into this form:

class CategoryForm(forms.Form):
   category = forms.CharField()
   createdon = forms.DateField()
   modifiedon = forms.DateField()
   test2 = forms.ChoiceField()
   this_is_a_test_field = forms.MultipleChoiceField()


Not the greatest example but you get the idea. I've found it useful
for when I need to tweak a couple of fields (which isn't easy without
defining the whole form).

Enjoy,

Felix

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---