Translate db api in model

0 views
Skip to first unread message

Burhan

unread,
Dec 26, 2005, 6:55:07 AM12/26/05
to Django users
Hello:

I'm having a problem trying to convert something that works great on
the python interpreter into the model.

I need to set a property of a model before it is saved. This propery
is dependent on the primary key (serial) of the record. I tried first
to do it using _post_save() but the id value was 'None'. So when I put
it _pre_save() I need to get the next id in the sequence. At the
python prompt, I can get the current max id using:

>>> from django.models.backend import workorders
>>> workorders.get_values(fields=['id'])[-1:][0]['id']
9

I need to get the same number in the model, which I tried using:

def _pre_save(self):
lastid = self.get_values(fields=['id'])[-1:][0]['id']
self.wonum = 'WO-'+lastid+1

I get the following error. 'WorkOrder' object has not attribute
'get_values'. Any ideas?

Regards,
Burhan

Andreas Stuhlmüller

unread,
Dec 26, 2005, 7:09:26 AM12/26/05
to django...@googlegroups.com
> I get the following error. 'WorkOrder' object has not attribute
> 'get_values'. Any ideas?

Try this:

def _pre_save(self):
lastid = get_values(fields=['id'])[-1]['id']
self.wonum = 'WO-'+lastid+1

Andreas

Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages