Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » manipulator save object is Not Implemented? [RSS Feed]

#1 Oct. 25, 2005 09:52:29

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

manipulator save object is Not Implemented?


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,
password=new_data,
first_name=new_data,
last_name=new_data,
email=new_data,
birth_date=new_data
)

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)
Object.save()This eliminates the need of updating manipulator code whenever fieldsare changed. And those +'_id' take care of foreign key fields.

Offline

#2 Oct. 25, 2005 23:03:54

A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

manipulator save object is Not Implemented?


Thanks very much. It is useful.

Armin

Offline

  • Root
  • » Django
  • » manipulator save object is Not Implemented? [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support