admin用于编辑特定用户

时间:2013-02-15 00:12:26

标签: python django

我让用户注册了我的网站。我希望能够编辑他们的“出价”。基本上,我希望能够转到admin / user / user-bid / 73,其中73是特定用户的ID,并且能够编辑他们的出价信息。我怎么能这样做?

我在admin.py中有以下内容:

class UserBidAdmin(admin.ModelAdmin):
    def queryset(self, request):
        return self.model.objects.filter(user = request.user)

create_modeladmin(UserBidAdmin, name='user-bid', model=Bid)



def create_modeladmin(modeladmin, model, name = None):
    class  Meta:
        proxy = True
        app_label = model._meta.app_label

    attrs = {'__module__': '', 'Meta': Meta}

    newmodel = type(name, (model,), attrs)

    admin.site.register(newmodel, modeladmin)
    return modeladmin

感谢。

1 个答案:

答案 0 :(得分:0)

class BidInline(admin.TabularInline):
    model = Bid


class UserWithProfileAdmin(UserAdmin):
    ..........

    inlines = [BidInline]


admin.site.unregister(User)
admin.site.register(User, UserWithProfileAdmin)