Manipulator Script
The attached script will produce a custom manipulator for the specified model. Useful if you've got a complex model which requires a slight change to the manipulator.
This is an interesting script to combine with ScaffoldScript
The new version will turn this model:
class Category(meta.Model): category = meta.CharField(maxlength=50, unique=True) createdOn = meta.DateField(auto_now_add=True) modifiedOn = meta.DateField(auto_now=True) test = meta.ManyToManyField(auth.User, verbose_name='test', related_name='test') test2 = meta.OneToOneField(auth.User, verbose_name='test2', related_name='test2') def __repr__(self): return "%s" % (self.category,) class META: admin = meta.Admin()
into this (using $ ./manipulator.py -a ToDo -m Category --name CustomToDo
class CustomCatManipulator(formfields.Manipulator): def __init__(self, pk=None): self.fields = ( formfields.TextField(field_name='category', is_required=True, maxlength=50), formfields.DateField(field_name='createdOn'), formfields.DateField(field_name='modifiedOn'), formfields.OneToOneField(field_name='test2', is_required=True), formfields.SelectMultipleField(field_name='test', is_required=True, choices=[(o.id, o) for o in tests.get_list()]), ) def save(self, new_data): temp = Category( category=new_data['category'], createdOn=new_data['createdOn'], modifiedOn=new_data['modifiedOn'], test2=new_data['test2'] ) temp.set_test(newdata['test']) temp.save() return temp
Attachments
- manipulator.py (2.5 kB) -
The script itself
, added by Lllama on 03/08/06 06:09:14. - manipulator.2.py (2.5 kB) -
Now adds M2M fields
, added by Lllama on 03/08/06 11:45:14. - manipulator.3.py (3.0 kB) -
Added a save method
, added by Lllama on 03/09/06 04:01:15. - manipulator.4.py (3.7 kB) -
Added better handling of M2M fields etc
, added by Lllama on 03/15/06 09:25:00. - manipulator.5.py (3.7 kB) -
Added 2.3 fix
, added by Lllama on 03/15/06 10:09:42. - make_manipulator.py (4.7 kB) -
made it work with post-magic-removal code, added some fixes and a project parameter
, added by Le Roux Bodenstein on 06/26/06 08:06:23.
