Re: About extending User model

2010-03-26 Thread Jim N
Carl, scratch my last message.  It does work.  Woot!  Thanks very
much.

On Mar 26, 2:39 pm, Jim N  wrote:
> On Mar 26, 1:39 pm, Carl Zmola  wrote:
>
>
>
>
>
> > On 03/25/2010 02:37 PM, Jim N wrote:
> > > Very interesting, Tom.
>
> > > I have inserted this code, substituting my profile model name
> > > (QotdUser) for UserProfile.  It does create a row in QotdUser, but the
> > > row is empty of course.
>
> > > More importantly, if I create a user via the admin interface (http://
> > > 127.0.0.1:8000/admin/auth/user/add/) there's no apparent way to edit
> > > any of the fields of my profile model.
>
> > > Or if I create the user some other way, would I be able to pass
> > > arguments to the User model to populate the profile?
>
> > > Finally, how do I access the profile, is it like
>
> > >    my_user_profile = User.objects.get(username="jim").get_profile() ?
>
> > > Thanks for the help.
>
> > I have done this, and I think the following link will 
> > helphttp://pyxx.org/2008/08/18/how-to-extend-user-model-in-django-and-ena...
>
> > You need to unregister the current model admin for the user model and
> > create a new one (based on the old one) that includes your user profile
> > "inline".
> > When you understand that last sentence, you will understand what is
> > going on.
>
> > Good luck.
>
> > --
> > Carl Zmola
> > czm...@woti.com
>
> Hi Carl,
>
> I've done just what you spelled out, I think, but I don't see any
> change in the Home › Auth › Users admin panel.  When editing the
> individual users, I can edith the fields that are part of the built-in
> User model, but not of the profile model.
>
> Here is the code:http://dpaste.de/OHwA/
>
> Here is the relevant part:
>
> -=-=-=-=-=-=-=-=-=-=-=-=
>
> class UserProfileInline(admin.TabularInline):
>     model = QotdUser
>     fk_name = 'user'
>     max_num = 1
>     list_display  = ('identifier', 'service', 'location',
> 'featured_status',)
>     list_filter   = ('featured_status', 'service',)
>     search_fields = ('identifier',)
>     exclude = ('alternate_id', 'questions_proposed_cnt',
> 'questions_published_cnt', 'answers_cnt')
>
> class MyUserAdmin(UserAdmin):
>     inlines = [UserProfileInline, ]
>
> admin.site.unregister(User)
>
> admin.site.register(User, MyUserAdmin)
>
> -=-=-=-=-=-=-=-=-=-=-=-=
>
> Am I missing a class there?
>
> Regards,
> Jim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: About extending User model

2010-03-26 Thread Jim N
On Mar 26, 1:39 pm, Carl Zmola  wrote:
> On 03/25/2010 02:37 PM, Jim N wrote:
> > Very interesting, Tom.
>
> > I have inserted this code, substituting my profile model name
> > (QotdUser) for UserProfile.  It does create a row in QotdUser, but the
> > row is empty of course.
>
> > More importantly, if I create a user via the admin interface (http://
> > 127.0.0.1:8000/admin/auth/user/add/) there's no apparent way to edit
> > any of the fields of my profile model.
>
> > Or if I create the user some other way, would I be able to pass
> > arguments to the User model to populate the profile?
>
> > Finally, how do I access the profile, is it like
>
> >    my_user_profile = User.objects.get(username="jim").get_profile() ?
>
> > Thanks for the help.
>
> I have done this, and I think the following link will 
> helphttp://pyxx.org/2008/08/18/how-to-extend-user-model-in-django-and-ena...
>
> You need to unregister the current model admin for the user model and
> create a new one (based on the old one) that includes your user profile
> "inline".
> When you understand that last sentence, you will understand what is
> going on.
>
> Good luck.
>
> --
> Carl Zmola
> czm...@woti.com


Hi Carl,

I've done just what you spelled out, I think, but I don't see any
change in the Home › Auth › Users admin panel.  When editing the
individual users, I can edith the fields that are part of the built-in
User model, but not of the profile model.

Here is the code: http://dpaste.de/OHwA/

Here is the relevant part:

-=-=-=-=-=-=-=-=-=-=-=-=

class UserProfileInline(admin.TabularInline):
model = QotdUser
fk_name = 'user'
max_num = 1
list_display  = ('identifier', 'service', 'location',
'featured_status',)
list_filter   = ('featured_status', 'service',)
search_fields = ('identifier',)
exclude = ('alternate_id', 'questions_proposed_cnt',
'questions_published_cnt', 'answers_cnt')

class MyUserAdmin(UserAdmin):
inlines = [UserProfileInline, ]

admin.site.unregister(User)

admin.site.register(User, MyUserAdmin)

-=-=-=-=-=-=-=-=-=-=-=-=

Am I missing a class there?

Regards,
Jim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: About extending User model

2010-03-26 Thread Carl Zmola



On 03/25/2010 02:37 PM, Jim N wrote:


Very interesting, Tom.

I have inserted this code, substituting my profile model name
(QotdUser) for UserProfile.  It does create a row in QotdUser, but the
row is empty of course.

More importantly, if I create a user via the admin interface (http://
127.0.0.1:8000/admin/auth/user/add/) there's no apparent way to edit
any of the fields of my profile model.

Or if I create the user some other way, would I be able to pass
arguments to the User model to populate the profile?

Finally, how do I access the profile, is it like

   my_user_profile = User.objects.get(username="jim").get_profile() ?

Thanks for the help.

   


I have done this, and I think the following link will help
http://pyxx.org/2008/08/18/how-to-extend-user-model-in-django-and-enable-new-fields-in-newforms-admin/

You need to unregister the current model admin for the user model and 
create a new one (based on the old one) that includes your user profile 
"inline".
When you understand that last sentence, you will understand what is 
going on.


Good luck.


--
Carl Zmola
czm...@woti.com


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: About extending User model

2010-03-25 Thread Jim N
Hi Peter,

I'm building an app where all logged-in users will be a Django user,
rather than creating some new separate class of users just for my own
app.

But to make it work, these users have to have more than the minimal
information contained in the django.contrib.auth.models User.  I
figure that's a fairly common situation.

I may create one class of users through Django's built-in admin.
Another class will be created via an API interface to my app.  In each
case, they need lots of detail missing from User.

Is my solution to create the User and update the profile separately
every time?  I can accept that it is, but was just looking for a more
tightly-coupled solution for extending the built-in user.

For example, I can't use django.contrib.auth.models User as a foreign
key in my models.  So how would I link a model instance (row) to a
user?  This is a question and answer site, so Answer would have a
foreign key of User, except that doesn't work.

Apologies if this is all spelled out somewhere and I just haven't
found it.

-Jim

On Mar 25, 5:18 pm, Peter Bengtsson  wrote:
> Generally, try to build your application so that it doesn't blindly
> depend on the profile existing. The signal example Tom showed you is
> good as it means you won't have to check if the UserProfile instance
> exists for the user on every turn. However, don't depend on the data
> within. Keep it light and separate.
> Why does the admin need the stuff you can put in UserProfile if you
> create him via the admin pages?
> If he really needs it, tell him to register and then you go in an turn
> his created account (in the admin) to a superuser or whatever you
> need.
>
> On 25 Mar, 18:37, Jim N  wrote:
>
>
>
> > On Mar 11, 1:03 pm, Tom Evans  wrote:
>
> > > On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> > > wrote:
> > > > I'm using UserProfile to add one field to my users. However, I know
> > > > that I must explicitly create UserProfile for each new user that
> > > > registers. So, I make a UserProfile upon registration. Is UserProfile
> > > > still the best way to extend the user model?
> > > > What about the admin user, or users that the admin creates? Since they
> > > > don't go through the registration process, how do I ensure that their
> > > > UserProfile gets created?
>
> > > Add this to your models.py
>
> > > from django.db.models.signals import post_save
> > > from django.contrib.auth.models import User
>
> > > def _hook_save_user(instance, sender, **kwargs):
> > >   try:
> > >     instance.get_profile()
> > >   except UserProfile.DoesNotExist:
> > >     UserProfile.objects.get_or_create(user=instance)
>
> > > post_save.connect(_hook_save_user, sender=User)
>
> > On Mar 11, 1:03 pm, Tom Evans  wrote:
>
> > > On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> > > wrote:
> > > > I'm using UserProfile to add one field to my users. However, I know
> > > > that I must explicitly create UserProfile for each new user that
> > > > registers. So, I make a UserProfile upon registration. Is UserProfile
> > > > still the best way to extend the user model?
> > > > What about the admin user, or users that the admin creates? Since they
> > > > don't go through the registration process, how do I ensure that their
> > > > UserProfile gets created?
>
> > > Add this to your models.py
>
> > > from django.db.models.signals import post_save
> > > from django.contrib.auth.models import User
>
> > > def _hook_save_user(instance, sender, **kwargs):
> > >   try:
> > >     instance.get_profile()
> > >   except UserProfile.DoesNotExist:
> > >     UserProfile.objects.get_or_create(user=instance)
>
> > > post_save.connect(_hook_save_user, sender=User)
>
> > Very interesting, Tom.
>
> > I have inserted this code, substituting my profile model name
> > (QotdUser) for UserProfile.  It does create a row in QotdUser, but the
> > row is empty of course.
>
> > More importantly, if I create a user via the admin interface (http://
> > 127.0.0.1:8000/admin/auth/user/add/) there's no apparent way to edit
> > any of the fields of my profile model.
>
> > Or if I create the user some other way, would I be able to pass
> > arguments to the User model to populate the profile?
>
> > Finally, how do I access the profile, is it like
>
> >   my_user_profile = User.objects.get(username="jim").get_profile() ?
>
> > Thanks for the help.
>
> > -Jim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: About extending User model

2010-03-25 Thread Peter Bengtsson
Generally, try to build your application so that it doesn't blindly
depend on the profile existing. The signal example Tom showed you is
good as it means you won't have to check if the UserProfile instance
exists for the user on every turn. However, don't depend on the data
within. Keep it light and separate.
Why does the admin need the stuff you can put in UserProfile if you
create him via the admin pages?
If he really needs it, tell him to register and then you go in an turn
his created account (in the admin) to a superuser or whatever you
need.

On 25 Mar, 18:37, Jim N  wrote:
> On Mar 11, 1:03 pm, Tom Evans  wrote:
>
> > On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> > wrote:
> > > I'm using UserProfile to add one field to my users. However, I know
> > > that I must explicitly create UserProfile for each new user that
> > > registers. So, I make a UserProfile upon registration. Is UserProfile
> > > still the best way to extend the user model?
> > > What about the admin user, or users that the admin creates? Since they
> > > don't go through the registration process, how do I ensure that their
> > > UserProfile gets created?
>
> > Add this to your models.py
>
> > from django.db.models.signals import post_save
> > from django.contrib.auth.models import User
>
> > def _hook_save_user(instance, sender, **kwargs):
> >   try:
> >     instance.get_profile()
> >   except UserProfile.DoesNotExist:
> >     UserProfile.objects.get_or_create(user=instance)
>
> > post_save.connect(_hook_save_user, sender=User)
>
> On Mar 11, 1:03 pm, Tom Evans  wrote:
>
>
>
> > On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> > wrote:
> > > I'm using UserProfile to add one field to my users. However, I know
> > > that I must explicitly create UserProfile for each new user that
> > > registers. So, I make a UserProfile upon registration. Is UserProfile
> > > still the best way to extend the user model?
> > > What about the admin user, or users that the admin creates? Since they
> > > don't go through the registration process, how do I ensure that their
> > > UserProfile gets created?
>
> > Add this to your models.py
>
> > from django.db.models.signals import post_save
> > from django.contrib.auth.models import User
>
> > def _hook_save_user(instance, sender, **kwargs):
> >   try:
> >     instance.get_profile()
> >   except UserProfile.DoesNotExist:
> >     UserProfile.objects.get_or_create(user=instance)
>
> > post_save.connect(_hook_save_user, sender=User)
>
> Very interesting, Tom.
>
> I have inserted this code, substituting my profile model name
> (QotdUser) for UserProfile.  It does create a row in QotdUser, but the
> row is empty of course.
>
> More importantly, if I create a user via the admin interface (http://
> 127.0.0.1:8000/admin/auth/user/add/) there's no apparent way to edit
> any of the fields of my profile model.
>
> Or if I create the user some other way, would I be able to pass
> arguments to the User model to populate the profile?
>
> Finally, how do I access the profile, is it like
>
>   my_user_profile = User.objects.get(username="jim").get_profile() ?
>
> Thanks for the help.
>
> -Jim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: About extending User model

2010-03-25 Thread Jim N
On Mar 11, 1:03 pm, Tom Evans  wrote:
> On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> wrote:
> > I'm using UserProfile to add one field to my users. However, I know
> > that I must explicitly create UserProfile for each new user that
> > registers. So, I make a UserProfile upon registration. Is UserProfile
> > still the best way to extend the user model?
> > What about the admin user, or users that the admin creates? Since they
> > don't go through the registration process, how do I ensure that their
> > UserProfile gets created?
>
> Add this to your models.py
>
> from django.db.models.signals import post_save
> from django.contrib.auth.models import User
>
> def _hook_save_user(instance, sender, **kwargs):
>   try:
>     instance.get_profile()
>   except UserProfile.DoesNotExist:
>     UserProfile.objects.get_or_create(user=instance)
>
> post_save.connect(_hook_save_user, sender=User)
>
On Mar 11, 1:03 pm, Tom Evans  wrote:
> On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> wrote:
> > I'm using UserProfile to add one field to my users. However, I know
> > that I must explicitly create UserProfile for each new user that
> > registers. So, I make a UserProfile upon registration. Is UserProfile
> > still the best way to extend the user model?
> > What about the admin user, or users that the admin creates? Since they
> > don't go through the registration process, how do I ensure that their
> > UserProfile gets created?
>
> Add this to your models.py
>
> from django.db.models.signals import post_save
> from django.contrib.auth.models import User
>
> def _hook_save_user(instance, sender, **kwargs):
>   try:
>     instance.get_profile()
>   except UserProfile.DoesNotExist:
>     UserProfile.objects.get_or_create(user=instance)
>
> post_save.connect(_hook_save_user, sender=User)
>

Very interesting, Tom.

I have inserted this code, substituting my profile model name
(QotdUser) for UserProfile.  It does create a row in QotdUser, but the
row is empty of course.

More importantly, if I create a user via the admin interface (http://
127.0.0.1:8000/admin/auth/user/add/) there's no apparent way to edit
any of the fields of my profile model.

Or if I create the user some other way, would I be able to pass
arguments to the User model to populate the profile?

Finally, how do I access the profile, is it like

  my_user_profile = User.objects.get(username="jim").get_profile() ?

Thanks for the help.

-Jim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: About extending User model

2010-03-11 Thread Tom Evans
On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  wrote:
> I'm using UserProfile to add one field to my users. However, I know
> that I must explicitly create UserProfile for each new user that
> registers. So, I make a UserProfile upon registration. Is UserProfile
> still the best way to extend the user model?
> What about the admin user, or users that the admin creates? Since they
> don't go through the registration process, how do I ensure that their
> UserProfile gets created?
>

Add this to your models.py

from django.db.models.signals import post_save
from django.contrib.auth.models import User

def _hook_save_user(instance, sender, **kwargs):
  try:
instance.get_profile()
  except UserProfile.DoesNotExist:
UserProfile.objects.get_or_create(user=instance)

post_save.connect(_hook_save_user, sender=User)

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.