On Tuesday, January 6, 2015 5:05:04 AM UTC-3, Cédric Krier wrote:
>
> On 05 Jan 21:58, Sergi Almacellas Abellana wrote:
> >
> >
> > On 5 de gener de 2015 21:18:45 CET, Mariano Ramon <[email protected]
> <javascript:>> wrote:
> > >Which is the function that runs on creations of any model.
> >
> > The create function of a model is called every time you create some
> records of the model.
> >
> > The signature is the following:
> >
> > def create(cls, vlist)
> >
> > where vlist is a list of dictionaries, where each dictionary a key value
> for each field of the model. The key is the name of the field, and the
> value is the value used to create the record.
>
> But this method should no more be recommended, the right one is: save()
> on instance.
>
>
Actually both answers are useful. I need a record to be saved with default
values on the creation of another. Is there any other better way to hook on
this event?, and if I have to use create.. how do I it without interfering
with the creation of the parent record?
> > And how can
> > >I
> > >instantiate and assign a different but related model to one of the
> > >fields
> > >of the first?
> >
> > Don't understand the question. Can you put clarify or put an example?
>
> I guess he means putting a value of a Many2One field.
>
> record = MyModel()
> target = MyTarget()
> target.save()
> record.target = target
> record.save()
>
>
yes this is what I would need to do when updating or creating "record"
would this be correct?:
class MyModel(ModelSQL, ModelView):
'MyModel'
__name__ = 'mymodel.mymodel'
@classmethod
def create(cls, vlist):
super(MyModel, cls).create(vlist)
target = MyTarget()
#
# set desired values here
#
target.save()
self.target = target
self.save()
thanks!
Mariano