Armin wrote:
I went ahead and defined the 'save' function under my custom defined
manipulator as follows:
def save(self, new_data):
p = persons.Person(username=new_data['username'],
password=new_data['password'],
first_name=new_data['first_name'],
last_name=new_data['last_name'],
email=new_data['email'],
birth_date=new_data['birth_date']
)
Is there any way to automate this any further?
There is. I do this in my project this way:
def save(self,data):
Object=objects.get_object(pk=self.id)
for field in self.fields:
if field.field_name+'_id' in Object.__dict__:
actual_field_name=field.field_name+'_id'
else:
actual_field_name=field.field_name
Object.__setattr__(actual_field_name,data[field.field_name])
Object.save()
This eliminates the need of updating manipulator code whenever fields
are changed. And those +'_id' take care of foreign key fields.