django-registration with my custom user profile

91 views
Skip to first unread message

Chr1s

unread,
Jun 13, 2008, 5:03:58 AM6/13/08
to Django users
Hi guys, I tried django-registration 0.5 today, it is powerful indeed,
but I have a site-specific user profile just like this writen in my
model.py

class Userdetail(models.Model):
user = models.ForeignKey(User, primary_key = True) #
nickname = models.CharField(max_length=30)
DOB = models.DateField()
country = models.CharField(max_length=30, default = "CN") #
province = models.CharField(max_length=30) #省份
city = models.CharField(max_length=15) #城市
gender = models.BooleanField() # male true, female false
phone = models.PhoneNumberField() # phone
ip = models.IPAddressField() # last login IP
bio = models.CharField(max_length=200) # bio for user
def_club = models.ForeignKey(ClubMember)

In the source code of django-registration, it said that
#To enable creation of a custom user profile along with the
# ``User`` (e.g., the model specified in the
# ``AUTH_PROFILE_MODULE`` setting), define a function which
# knows how to create and save an instance of that model with
# appropriate default values, and pass it as the keyword
# argument ``profile_callback``. This function should accept
one
# keyword argument:

# ``user``
# The ``User`` to relate the profile to.

But still I don't know how to implement this, anyone could give me a
simple example? thanks very much

James Bennett

unread,
Jun 13, 2008, 5:17:29 AM6/13/08
to django...@googlegroups.com
2008/6/13 Chr1s <kknd...@gmail.com>:

> But still I don't know how to implement this, anyone could give me a
> simple example? thanks very much

This feature is intended for a situation where each of the following is true:

1. You have a custom user-profile model.
2. The user-profile model has been written in such a way that an
instance can be created using nothing but default values (e.g., with
no input whatsoever from the user).

If that is the case, simply write a function which can create an
instance using nothing but default values, and pass that as the
argument.

If that is not the case, you will either need to write a more complex
custom form (to handle any additional information you want to collect)
or create the profile in a separate step (e.g., using
django-profiles).


--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

Chr1s

unread,
Jun 13, 2008, 5:07:44 AM6/13/08
to Django users
Hi guys I am newbie for django, today I tried django-registration, in
the source code it said that
-----------------------------------------------------------------------------------------------
To enable creation of a custom user profile along with the
``User`` (e.g., the model specified in the
``AUTH_PROFILE_MODULE`` setting), define a function which
knows how to create and save an instance of that model with
appropriate default values, and pass it as the keyword
argument ``profile_callback``. This function should accept one
keyword argument:

``user``
The ``User`` to relate the profile to.
----------------------------------------------------------------------------------------------------

I have a custom specific user profile like this

--------------------------------------------------------------------------------------------------------
class Userdetail(models.Model):
user = models.ForeignKey(User, primary_key = True) #
nickname = models.CharField(max_length=30)
DOB = models.DateField()
country = models.CharField(max_length=30, default = "CN") #
province = models.CharField(max_length=30) #
city = models.CharField(max_length=15) #
gender = models.BooleanField() #
phone = models.PhoneNumberField() #
ip = models.IPAddressField() #
bio = models.CharField(max_length=200) #
def_club = models.ForeignKey(ClubMember)

Chr1s

unread,
Jun 13, 2008, 6:02:47 AM6/13/08
to Django users
Hi thanks for your replay,
It is the second situation, I re-write the form.py like this

class RegistrationForm(forms.Form):
........ (other stuff )....
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'],

nickname = self.cleaned_data['nickname'],

country = self.cleaned_data['country'],

province = self.cleaned_data['province'],

city = self.cleaned_data['city'],

gender = self.cleaned_data['gender'],

phone = self.cleaned_data['phone'],

bio = self.cleaned_data['bio'],

profile_callback=profile_callback)
return new_user


and then I changed the models.py in this way.

def create_inactive_user(self, username, password,
email,dob,nickname,country,province,
city,gender,phone,bio,send_email=True,
profile_callback=None):
new_user =
User.objects.create_user(username,last_name,first_name, email,
password)
new_user.is_active = False
new_user.save()




registration_profile = self.create_profile(new_user)
userdetail =
UserDetail(new_user,nickname,dob,country,province,city,gender,phone,bio)
userdetail.save()
if profile_callback is not None:
profile_callback(user=new_user)

but the browser throw the error like this

TypeError at /veryuser/register/
create_inactive_user() takes at least 12 non-keyword arguments (4
given)


thanks



On Jun 13, 5:17 pm, "James Bennett" <ubernost...@gmail.com> wrote:
> 2008/6/13 Chr1s <kkndda...@gmail.com>:

Chr1s

unread,
Jun 14, 2008, 2:57:09 AM6/14/08
to Django users
any help:?

pihentagy

unread,
Jun 19, 2008, 5:31:11 AM6/19/08
to Django users
You didn't provide the 'dob' parameter.

pihentagy

unread,
Jun 25, 2008, 9:10:03 AM6/25/08
to Django users
Hi!

I'm also trying to use django-registration. In my case the userprofile
is mandatory, so I should create my own form. However, I would like to
use ModelForms for the UserProfile part, but I should also provide
room to enter username, and password. (and I also would like to store
additional data (first name, last name). Could anybody tell me how?

On Jun 13, 11:17 am, "James Bennett" <ubernost...@gmail.com> wrote:
> 2008/6/13 Chr1s <kkndda...@gmail.com>:
>
Reply all
Reply to author
Forward
0 new messages