1

我扩展了RegistrationFormUniqueEmail

class CustomRegistrationFormUniqueEmail(RegistrationFormUniqueEmail):
    first_name = forms.CharField(label=_('First name'), max_length=30,required=True)
    last_name = forms.CharField(label=_('Last name'), max_length=30, required=True)
    def save(self, profile_callback=None):
        new_user = super(CustomRegistrationFormUniqueEmail, self).save(profile_callback=profile_callback)
        new_user.first_name = self.cleaned_data['first_name']
        new_user.last_name = self.cleaned_data['last_name']
        return new_user

然后改变了看法

#       form = form_class(data=request.POST, files=request.FILES)
        form = CustomRegistrationFormUniqueEmail(data=request.POST, files=request.FILES)

但是,我仍然看到仅包含四个字段的默认表单。

4

3 回答 3

3

We recently implemented such a form. Here's what we've done:

  • Create a new backend (just copy it from the default backend to start with)

    registration/
        backends/
            default/
            custom/ # <- your new backend
    

    ...

  • In the new urls.py adjust the backend arguments

    ...
    { 'backend': 'registration.backends.custom.DefaultBackend' },
    ...
    
  • Create a forms.py under custom. Adjust this form to your liking (fields and validations)

  • In the registration/urls.py point to the proper backend:

     # from registration.backends.default.urls import *
     from registration.backends.custom.urls import *
    

That should work. Particularly this works because:

  • Your custom/__init__.py will have a DefaultBackend class with a get_form_class method:

    def get_form_class(self, request):
        """
        Return the default form class used for user registration.
        """
        return RegistrationForm
    
  • And you import your own RegistrationForm in that file, too:

    from registration.backends.custom.forms import RegistrationForm
    
于 2010-05-29T15:13:48.000 回答
0

您可以尝试在此处查看使用信号扩展 django-registration和此处http://dmitko.ru/?p=546

于 2010-06-26T19:23:18.783 回答
0

我不确定为什么它不起作用,但我很确定你不需要编辑 django-registration 的views.py......你可以将你的 newCustomRegistrationFormUniqueEmail作为参数传递给urls.py.

于 2010-05-29T13:24:18.653 回答