On 5/4/06, Matthew Flanagan <[EMAIL PROTECTED]> wrote: > Hi > > I've been porting a large application to MR since monday and have it > 99% done except for a few issues. One of them is the > _manipulator_validate_FIELD(self, field_data, all_data) methods not > being call for my models. Is this intended behaviour? > > I was able to turn some of the methods into regular validators, > however, with two others I need to check whether the manipulator is an > Add or a Change one and do things differently. If I turn these into > regular functions that I just add to the fields validator list how can > can I determine this? > > > cheer > > matthew >
(I know it's bad form to reply to my own email's but...) I just thought I should clarify what I was doing before with the _manipulator_validate_FIELD() model methods, how I've translated them to the latest post-MR trunk, and the problem I'm now facing. in pre-MR I had a model with: def _manipulator_validate_somefield(self, field_data, all_data); ... if getattr(self, 'original_object', None): # do something if we are changing the object else: # do something else if we are adding the object. I originally did things this way rather than using a custom manipulator so that I could just use the django admin and/or generic views to add/change my model data and everything would just work...as if by magic! Over time many of my application views moved to using my own "generic" views and the behaviour above still worked. Since MR merged the _manipulator_validate_FIELD() methods stopped working. The solution I came up with was to write custom manipulators (which was what I was trying to avoid all along). My solution so far is: # this was _manipulator_validate_somefield() def validateSomeField(manipulator, field_data, all_data): if getattr(manipulator, 'original_object', None): # do something if we are changing the object else: # do something else if we are adding the object. class MyModelAddManipulator(MyModel.AddManipulator): def __init__(self, follow=None): MyModel.AddManipulator.__init__(self, follow=follow) newfields = [] for field in self.fields: if field.field_name == "somefield": # want to insert our new validator before the last _curried one field.validator_list.insert(-1, self.validateSomeField) newfields.append(field) self.fields = newfields def validateSomeField(self, field_data, all_data): validateSomeField(self, field_data, all_data) class MyModelAddManipulator(MyModel.ChangeManipulator): def __init__(self, obj_key, follow=None): MyModel.ChangeManipulator.__init__(self, obj_key, follow=follow) newfields = [] for field in self.fields: if field.field_name == "somefield": # want to insert our new validator before the last _curried one field.validator_list.insert(-1, self.validateSomeField) newfields.append(field) self.fields = newfields def validateSomeField(self, field_data, all_data): validateSomeField(self, field_data, all_data) This is all fine except you can no longer use generic views or django admin to edit your model data as they will not use the new manipulators. Which is where I've hit the problem that some of my apps don't have their own views and I use the admin to edit them. Here's the bit where I want my cake and eat it too: Can I make the django admin app use my custom manipulators? If not then the immediate benefits of django's admin app are lost for me. matthew --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---