mongoengine
mongoengine copied to clipboard
bulk insert does not invoke pre_save or save() methods of the Document
Unconfirmed.objects.insert([Unconfirmed(shift=s) for s in nlu.items()])
and inside Unconfirmed class I have a save method that is never called during operation above. But if I do
[Unconfirmed(shift=s).save() for s in nlu.items()]
then everything works as expected. Do I miss something?
def save(self, *args, **kwargs):
"""
save handler
"""
if self.school:
if not self.department:
self.department = self.school.department
if not self.district:
self.district = self.school.district
# speed-up fields
self.supervisor = self.department.supervisor
self.supervisor_name = self.supervisor.fullname
self.supervisor_phone = self.supervisor.phone_cell or self.supervisor.phone_home
self.guard_name = self.guard.fullname
self.guard_phone = self.guard.phone_cell or self.guard.phone_home
self.department_name = self.department.name
self.department_code = self.department.code
self.district_name = self.district.name
self.district_code = self.district.code
self.school_name = self.school.name
self.school_phone = self.school.phone
self.school_code = self.school.code
self.shift_start_sec = self.shift.start_sec
self.shift_finish_sec = self.shift.finish_sec
self.location_cache = self.location
self.shift_cache = self.shift
return super(Unconfirmed, self).save(*args, **kwargs)