This question has been flagged
1 Reply
2748 Views

I have the following models Program, Course, ProgramAdmission, CourseEnrollment.

Each course is associated with a program.


During program admission, I am showing the list of available courses for the selected program. For each shown course, I want to show a dropdown menu with the following selections: Not Planned and Planned.


Now if the user saves the new program admission, I want also to enroll the user in the planned courses by creating CourseEnrollment in the server-side for each planned course.


And if the user discards the new program admission, nothing should be created in the database.


How can I allow for such conditional batch creation of model objects?


Thank you!

Avatar
Discard
Best Answer

I think the solution is to override create method:

Here the question is why we need to override these (create, write and unlink) methods.The answer is to add or remove additional functionality we use overriding.

class Campus(models.Model):
    _name='campus'    
    @api.model
    def create(self,values):
        campus_create = super(Campus,self).create(values)
        return campus_create


Reference: https://goo.gl/4BkizH

Avatar
Discard