Changes between Version 20 and Version 21 of CookBookNewformsAdminAndUser
- Timestamp:
- Oct 12, 2011, 9:55:59 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CookBookNewformsAdminAndUser
v20 v21 28 28 fields = ('content',) 29 29 30 class Post ModelAdmin(admin.ModelAdmin):30 class PostAdmin(admin.ModelAdmin): 31 31 32 32 fields= ('content',) … … 34 34 35 35 def save_model(self, request, obj, form, change): 36 37 instance = form.save(commit=False) 38 39 instance.user = request.user 40 41 instance.save() 42 43 form.save_m2m() 44 45 return instance 36 obj.user = request.user 37 obj.save() 46 38 47 39 def save_formset(self, request, form, formset, change): 48 49 def set_user(instance):50 instance.user = request.user51 instance.save()52 53 40 if formset.model == Comment: 54 41 instances = formset.save(commit=False) 55 map(set_user, instances)56 formset.save_m2m()57 return instances42 for instance in instances: 43 instance.user = request.user 44 instance.save() 58 45 else: 59 returnformset.save()46 formset.save() 60 47 61 48 admin.site.register(Post, PostModelAdmin)