小编cod*_*joe的帖子

从Django Auth中的UserChangeForm中排除用户名或密码

我正在试图找出如何从中排除用户名和/或密码的方法UserChangeForm.我试过了两个exclude,fields但我不适用于这两个领域.

这是一些代码:

class ArtistForm(ModelForm):
    class Meta:
        model = Artist
        exclude = ('user',)

class UserForm(UserChangeForm):
    class Meta:
        model = User
        fields = (
            'first_name',
            'last_name',
            'email',
            )
        exclude = ('username','password',)

    def __init__(self, *args, **kwargs):
        self.helper = FormHelper
        self.helper.form_tag = False
        super(UserForm, self).__init__(*args, **kwargs)
        artist_kwargs = kwargs.copy()
        if kwargs.has_key('instance'):
            self.artist = kwargs['instance'].artist
            artist_kwargs['instance'] = self.artist
        self.artist_form = ArtistForm(*args, **artist_kwargs)
        self.fields.update(self.artist_form.fields)
        self.initial.update(self.artist_form.initial)

    def clean(self):
        cleaned_data = super(UserForm, self).clean()
        self.errors.update(self.artist_form.errors)
        return cleaned_data

    def save(self, commit=True):
        self.artist_form.save(commit)
        return super(UserForm, …
Run Code Online (Sandbox Code Playgroud)

django django-forms django-authentication django-users

9
推荐指数
2
解决办法
4414
查看次数

Django is_ajax历史回归

我写了一个Django视图,响应以太text/html或一个application/json依赖request.is_ajax().到目前为止一切都那么好,但是当我使用浏览器历史记录按钮时,我最终得到的是JSON响应,而不是HTML.

我无法弄清楚这个问题.这是真的一个jQuery ajax请求在页面加载后获得相同的URL,但这不应该在历史记录中结束,还是应该?

谢谢,乔

python django ajax jquery django-views

2
推荐指数
1
解决办法
435
查看次数