Changes between Version 8 and Version 9 of CookBookNewformsAdminAndUser
- Timestamp:
- Aug 9, 2008, 2:21:23 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CookBookNewformsAdminAndUser
v8 v9 17 17 content = models.TextField() 18 18 19 class Comment(models.Model): 20 post = models.ForeignKey(Post) 21 user = models.ForeignKey(User) 22 content = models.TextField() 23 19 24 # app/admin.py 20 25 21 from app.models import Post 26 from app.models import Post, Comment 22 27 from django.contrib import admin 28 29 class CommentInline(admin.TabularInline): 30 model = Comment 31 fields = ('content',) 23 32 24 33 class PostModelAdmin(admin.ModelAdmin): 25 34 26 35 fields= ('content',) 36 inlines = [CommentInline] 27 37 28 38 def save_model(self, request, form, change): 29 39 30 new_object= form.save(commit=False)40 instance = form.save(commit=False) 31 41 32 new_object.user = request.user33 new_object.save()42 instance.user = request.user 43 instance.save() 34 44 35 45 form.save_m2m() 36 46 37 return new_object 47 return instance 48 49 def save_formset(self, request, formset, change): 50 51 instances = formset.save(commit=False) 52 53 for instance in instances: 54 55 instance.user = request.user 56 instance.save() 57 58 formset.save_m2m() 38 59 39 60 admin.site.register(Post, PostModelAdmin)