Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Setup</strong></p> <p>Are you using the <a href="http://bitbucket.org/ubernostrum/django-profiles/wiki/Home" rel="noreferrer">django-profiles</a> and <a href="http://bitbucket.org/ubernostrum/django-registration/wiki/Home" rel="noreferrer">django-registration</a> projects? If not, you should&mdash;much of this code has already been written for you.</p> <p><strong>Profile</strong></p> <p>Your user profile code is:</p> <pre><code>class Profile(models.Model): user = models.ForeignKey(User, unique=True) born = models.DateTimeField('born to') photo = models.ImageField(upload_to='profile_photo') </code></pre> <p>Have you correctly setup this profile in your Django settings? You should add this if not, substituting <code>yourapp</code> for your app's name:</p> <pre><code>AUTH_PROFILE_MODULE = "yourapp.Profile" </code></pre> <p><strong>Registration Form</strong></p> <p><code>django-registration</code> comes with some default registration forms but you specified you wanted to create your own. Each <a href="http://docs.djangoproject.com/en/1.1/ref/forms/fields/#required" rel="noreferrer">Django form field defaults to required</a> so you should not need to change that. The important part is just making sure to handle the existing registration form fields and adding in the profile creation. Something like this should work:</p> <pre><code>from django import forms from registration.forms import RegistrationForm from yourapp.models import Profile from registration.models import RegistrationProfile class YourRegistrationForm(RegistrationForm): born = forms.DateTimeField() photo = forms.ImageField() def save(self, profile_callback=None): new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'], password=self.cleaned_data['password1'], email = self.cleaned_data['email']) new_profile = Profile(user=new_user, born=self.cleaned_data['born'], photo=self.cleaned_data['photo']) new_profile.save() return new_user </code></pre> <p><strong>Bringing it together</strong></p> <p>You can use the default <code>django-registration</code> templates and views, but will want to pass them your form in <code>urls.py</code>:</p> <pre><code>from registration.backends.default import DefaultBackend from registration.views import activate from registration.views import register # ... the rest of your urls until you find somewhere you want to add ... url(r'^register/$', register, {'form_class' : YourRegistrationForm, 'backend': DefaultBackend}, name='registration_register'), </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload