On Aug 20, 10:27 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm trying to save user info automatically via admin interface. I
> found an example in code.djangoproject.com/wiki/
> CookBookNewformsAdminAndUser and tested it out. It doesn't work. I got
> the following error:
>
> =============
> TypeError at /admin/geo_note/post/add/
>
> save_model() got multiple values for keyword argument 'change'
>
> Request Method:         POST
> Request URL:    http://localhost:8000/admin/geo_note/post/add/
> Exception Type:         TypeError
> Exception Value:
>
> save_model() got multiple values for keyword argument 'change'
>
> Exception Location:     C:\python25\lib\site-packages\django\contrib\admin
> \options.py in add_view, line 490
> Python Executable:      C:\python25\python.exe
> Python Version:         2.5.1
> =============
>
> The code is like this:
>
> =============
> # coding=utf-8
>
> # app/models.py
>
> from django.db import models
> from django.contrib.auth.models import User
>
> class Post(models.Model):
>     user = models.ForeignKey(User)
>     content = models.TextField()
>
> class Comment(models.Model):
>     post = models.ForeignKey(Post)
>     user = models.ForeignKey(User)
>     content = models.TextField()
>
> # app/admin.py
>
> #from app.models import Post, Comment
> from django.contrib import admin
>
> class CommentInline(admin.TabularInline):
>     model = Comment
>     fields = ('content',)
>
> class PostModelAdmin(admin.ModelAdmin):
>
>     fields= ('content',)
>     inlines = [CommentInline]
>
>     def save_model(self, request, form, change):
>         instance = form.save(commit=False)
>         instance.user = request.user
>         instance.save()
>         form.save_m2m()
>         return instance
>
>     def save_formset(self, request, form, formset, change):
>
>         def set_user(instance):
>             instance.user = request.user
>             instance.save()
>
>         if formset.__name__ == 'CommentInline':
>             instances = formset.save(commit=False)
>             map(set_user, instances)
>             formset.save_m2m()
>             return instances
>         else:
>             return formset.save()
>
> admin.site.register(Post, PostModelAdmin)
> =============
>
> Any ideas?
> Regards,
> hvedur

hi, in the latest version:
http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/options.py?rev=8433#L360
the signature for save_model is:
def save_model(self, request, obj, form, change)

there may have been a version with the signature you have above...

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to