Hi,
Working on a Django app, which requires profile for each subscribing
user, I created a Profile model:
class Profile(models.model):
user = models.ForeignKey(User, unique=True)
middlename = models.CharField(max_length=32, blank=True)
gender = models.CharField(max_length=1, blank=True, null=True,
choices=GENDER_LIST)
last_updated = models.DateTimeField(auto_now=True)
Then, there is another apps installed, which handles the registration.
On successful activation of account, I need to create the entry in
django.contrib.auth.models.User as well as this Profile. Right now,
what I am doing is :
def create_account(username, password, firstname, lastname, email):
new_user = User.objects.create_user(
username=username,
email=email,
password=password
) # This will create entry in
new_user.is_active = True
new_user.first_name = firstname
new_user.last_name = lastname
new_user.save()
# Create Extended profile
up=UserProfile.objects.create(user=new_user)
up.firstname = new_user.first_name
up.lastname = new_user.last_name
up.save()
return True
# ----
But I feel somehow, there would be better way to do this. Like, I can
use signals (though not much familiar with this) or other way. Can
anyone suggest me some better way, methods, algo, so the code be
elegant, more understandable, better flow and more pythonic.
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---