How to use save_m2m method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...42 self.initial['students_in_class'] = [values[0] for values in pk_list]43 def save(self, commit=True):44 instance = super(ClassroomAdminForm, self).save(commit)45 46 def save_m2m():47 '''48 when a form is saved w/o commit, the save function must add save_m2m49 method to the instance for futher use50 '''51 instance.students = self.cleaned_data['students_in_class']52 print 'in form, students = ', instance.students.all()53 if commit:54 save_m2m() # if commit, call save_m2m55 elif hasattr(self, 'save_m2m'):56 # in case there are existing m2m57 save_old_m2m = self.save_m2m58 def save_both():59 save_old_m2m()60 save_m2m()61 self.save_m2m = save_both62 else:63 self.save_m2m = save_m2m64 return instance65 save.alters_data = True66class ClassroomAdmin(admin.ModelAdmin):67 form = ClassroomAdminForm68 list_display = ('year',69 'academic_year',70 )71 list_filter = ('year',), StudentAdmin)...

Full Screen

Full Screen Github


Full Screen

...9 }10 if request and request.user.is_authenticated():11 kwargs['owner'] = request.user12 instance = Video.from_vidscraper_video(**kwargs)13 def save_m2m():14 instance.save_m2m()15 if commit:16 save_m2m()18 else:19 self.save_m2m = save_m2m20 return instance21class CreateFeedForm(forms.ModelForm):22 def save(self, commit=True, request=None):23 if request and request.user.is_authenticated():24 self.instance.owner = request.user25 instance = super(CreateFeedForm, self).save(commit)26 if commit:27 instance.start_import()28 else:29 old_save_m2m = self.save_m2m30 def save_m2m():31 old_save_m2m()32 instance.start_import()33 self.save_m2m = save_m2m...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?