user registration help please

44 views
Skip to first unread message

psychok7

unread,
Apr 21, 2012, 1:28:05 AM4/21/12
to django...@googlegroups.com
hi there, i am quite new to django and i am having a little trouble extending my User with Userprofile. i have read lots of documentation about it and i have implemented as an extension of https://bitbucket.org/ubernostrum/django-registration a version but i am not sure it works the way its supposed to. basically when i create a new user (in admin view), only the basic built in fields show up, but my new fields don't.. on the other hand my database seems to be ok with one table for user and another for user profile with the ids matching. can you guys help me and let me know wht am i doing wrong and whats the correct way? PLEASE don't refer me back to the documentation because i have read it all

here is my code:

i also added AUTH_PROFILE_MODULE = 'registration.UserProfile' in settings.py

Brandy

unread,
Apr 21, 2012, 9:48:07 AM4/21/12
to django...@googlegroups.com
Have you made an admin.py file? It should look something like this:
 
from polls.models import Poll
from django.contrib import admin
 
admin.site.register(Poll)

Brandy

unread,
Apr 21, 2012, 9:50:27 AM4/21/12
to django...@googlegroups.com
Have you created an admin.py file? It should look something like this:
 
from poll.models import Poll
from django.contrib import admin
 
admin.site.register(Poll)
 

On Saturday, April 21, 2012 12:28:05 AM UTC-5, psychok7 wrote:

Ejah

unread,
Apr 21, 2012, 10:29:40 AM4/21/12
to Django users
If I am not mistaken you are editting the Registration source files.
There is no need to do that.
Simply add a new App. Create your user profile class in its models.py
file, name it whatever you like. Add registration and your App to the
installed_apps in your settings file. Edit the settings file and make
your model class the userprofile USER_PROFILE=yourclassname
Add the urls from django-registration to your projects urls.py.
Register your model in the admin, syncdb and your profile will show
up.
You can read the docs on djangoproject.com on how to do that, its
easy.
The docs on registration are short but accurate, and the source is
well documented.
Hth

On 21 apr, 15:50, Brandy <brandy.norri...@yahoo.com> wrote:
> Have you created an admin.py file? It should look something like this:
>
> from poll.models import Poll
> from django.contrib import admin
>
> admin.site.register(Poll)
>
>
>
> On Saturday, April 21, 2012 12:28:05 AM UTC-5, psychok7 wrote:
> > hi there, i am quite new to django and i am having a little trouble
> > extending my User with Userprofile. i have read lots of documentation about
> > it and i have implemented as an extension of
> >https://bitbucket.org/ubernostrum/django-registrationa version but i am

psychok7

unread,
Apr 21, 2012, 10:38:51 AM4/21/12
to django...@googlegroups.com
its seemed to work, thanks 
from django.contrib import admin

from registration.models import RegistrationProfile , UserProfile


class RegistrationAdmin(admin.ModelAdmin):
    list_display = ('__unicode__', 'activation_key_expired')
    search_fields = ('user__username', 'user__first_name')


admin.site.register(RegistrationProfile, RegistrationAdmin)
admin.site.register(UserProfile)

is this the correct way to do this? the associacions are there now in admin

psychok7

unread,
Apr 21, 2012, 10:42:42 AM4/21/12
to django...@googlegroups.com
Ejah i did that because in registration source code there are some values in Profile_callback set to NONE.. should i leave it like that?? the comments say i should change it and equal it to my user profile. is that it or i am doing it the wrong way?

Brandy

unread,
Apr 21, 2012, 11:41:21 AM4/21/12
to django...@googlegroups.com
It looks correct. Is everything showing up now?

psychok7

unread,
Apr 21, 2012, 12:04:05 PM4/21/12
to django...@googlegroups.com
thanks guys, i also did some tests without changing the registration source by doing get_profile() and it seems to work fine so i guess the less i touch it the better

Ejah

unread,
Apr 21, 2012, 5:33:32 PM4/21/12
to Django users
Hi,
What version of django-registration are you using? I assume 0.7
The usage of profile_callback has been removed in 0.8, a very recent
release actually, looking at the codebase history.
The finer documentation on the usage of 0.8 is made available at:
http://docs.b-list.org/django-registration/0.8/

What you are looking for was originally provided for in django-
profiles, which integrated nicely with django-registration.

However, the way to go now is to create a new app, add your user
profile class there, and connect to the
registration.signals.user_registered signal.

Small example:

models.py (in myapp)
from django.db import models
from registration.signals import user_registered
from django.dispatch import receiver

class MySuperDuperUserProfile(models.Model):
user = models.ForeignKey(User)
whatever = models.CharField(max_length=100)
wherever = models.CharField(max_length=50)

@receiver(user_registered)
def create_superduper_user_profile(sender, **kwargs):
new_user = kwargs.pop('user', None)
data_dict_from_registration_form = kwargs.pop('request',
None).POST
sdup = MySuperDuperUserProfile()
sdup.user = new_user
sdup.whatever = data_dict_from_registration_form['whatever']
sdup.wherever = data_dict_from_registration_form['wherever']
sdup.save()

That's all folks. No messing around with existing code. You can create
a custom registration form in which you add your profile fields, that
you pass to the registration view via de url, and get the form fields
from the request that also gets sent to the
create_superduper_user_function. Please note I did not run this sample
code, so some bugs certainly will be there.
HTH
Cheers
> > > >https://bitbucket.org/ubernostrum/django-registrationaversion but i

psychok7

unread,
Apr 21, 2012, 5:46:20 PM4/21/12
to django...@googlegroups.com
yes 0.7 , well ill give it a try then :) if i run into problems i will bother you a little bit further

Ejah

unread,
Apr 21, 2012, 5:51:18 PM4/21/12
to Django users
No problem. You would need to upgrade to 0.8 to make this work.
Enjoy!

psychok7

unread,
Apr 21, 2012, 7:23:38 PM4/21/12
to django...@googlegroups.com
i upgraded to 0.8 and start doing things your way and it seems to work fine. i just have one question, is this code OK or yours is better? if yes why is that?

    def create_user_profile(sender, instance, created, **kwargs):
        if created:
            UserProfile.objects.create(user=instance)
    post_save.connect(create_user_profile, sender=User)

Ejah

unread,
Apr 22, 2012, 1:30:41 AM4/22/12
to Django users
It seems to me you that with 'if created:' are testing for something
that is either already happened, or you already have an exception.
'created' is taking the place of the request object. And the request
object not necessarily contains valid POST data, but will exist, so
the test will pass always.
Look at the register function code in registation.models:
username, email, password = kwargs['username'], kwargs['email'],
kwargs['password1']
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(request)
new_user =
RegistrationProfile.objects.create_inactive_user(username, email,

password, site)
signals.user_registered.send(sender=self.__class__,
user=new_user,
request=request)
return new_user
"
The signal only goes out if a new_user has been created succesfully,
or an exception will have been riased.
Finally, the signal is only sent from this function.
You could argument that in the future you might have an alternative
'register' function that might do things differently. In that case I
would test the vailidity of the user object and the request.POST data.
HTH
Cheers
Reply all
Reply to author
Forward
0 new messages