Code

Changes between Version 20 and Version 21 of CookBookNewformsAdminAndUser


Ignore:
Timestamp:
10/12/11 07:55:59 (3 years ago)
Author:
apollo13
Comment:

clean up the example to make it easier to understand for new users...

Legend:

Unmodified
Added
Removed
Modified
  • CookBookNewformsAdminAndUser

    v20 v21  
    2828    fields = ('content',) 
    2929 
    30 class PostModelAdmin(admin.ModelAdmin): 
     30class PostAdmin(admin.ModelAdmin): 
    3131 
    3232    fields= ('content',) 
     
    3434 
    3535    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() 
    4638 
    4739    def save_formset(self, request, form, formset, change):  
    48  
    49         def set_user(instance): 
    50             instance.user = request.user 
    51             instance.save() 
    52  
    5340        if formset.model == Comment: 
    5441            instances = formset.save(commit=False) 
    55             map(set_user, instances) 
    56             formset.save_m2m() 
    57             return instances 
     42            for instance in instances: 
     43                instance.user = request.user 
     44                instance.save() 
    5845        else: 
    59             return formset.save() 
     46            formset.save() 
    6047 
    6148admin.site.register(Post, PostModelAdmin)