Skip to Content
Menu
This question has been flagged
1 Reply
2857 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
Related Posts Replies Views Activity
0
Apr 24
554
0
Dec 19
3493
5
Dec 19
2488
0
Aug 19
4
5
Aug 19
1782