Hi, currently I have three model - model A with a one2one relationship to model B, and model B has a one2many relationship to model C. When I click on a button in model A, a wizard of model B will be automatically populated with all the fields and model C records as well.
There’s a rule on model C which restricts user Dave from seeing/editing user Tom’s record. However all the records would need to be created by user Dave. Upon creation, user Dave can only view/edit its own records and user Tom can only view/edit its own records as well.
May I know how can I achieve this? I tried adding a default boolean to allow user A to create record, but am unable to set it to False upon creation. Example codes I’ve tried:
def create(cls, vlist): records = super(Class, cls).create(vlist) for record in records: record.first_time_check = False Class.save(records) #this line will prompt bypass rule error update_query = "UPDATE class SET first_time_check = %s" cursor.execute(update_query, (False,)) #this won't prompt bypass rule error but won't work as well. #the records returned is still True. return records
Is there a method like def post_create that will only run after the create method so that I can update the field? I tried on_change but I am unable to trigger it after creating the records