I'll give that a shot.  Thank you for your feedback. Still learning a lot as
I go.

On Tue, Mar 1, 2011 at 8:07 PM, Stefano <s.apostol...@gmail.com> wrote:

> why you don't create the profile only if needed ?
>
> class UserProfile(models.Model):
>    user = models.ForeignKey(User, unique=True)
>
> User.profile = property(lambda u:
> UserProfile.objects.get_or_create(user=u)[0])
>
> 2011/3/2 Jeremiah <wanderinweez...@gmail.com>:
> > Hi All,
> >
> > I'm going through the help document (http://docs.djangoproject.com/en/
> > 1.2/topics/auth/#storing-additional-information-about-users) and I'm
> > starting to figure out how signals work.  What I'm having problems
> > with is getting my signal to trigger (or at least figuring out if the
> > signal is actually triggering?)
> >
> > So, if I do the following from the shell (as spawned by manage.py):
> >>>> import cc.models
> >>>> from django.contrib.auth.models import User
> >>>> u = User.objects.get(username__exact="duh3")
> >>>> try:
> > ...     u.userprofile
> > ... except:
> > ...     profile = cc.models.UserProfile()
> > ...     profile.user = u
> > ...     profile.thing = "Test"
> > ...     profile.save()
> > ...
> > <UserProfile: duh3>
> >>>> u.userprofile.user
> > <User: duh3>
> >>>> u.userprofile.thing
> > u'Test'
> >
> > I can get the profile to work.  So, then I add the following lines to
> > my "models.py" file:
> > from django.db.models.signals import post_save
> > ...
> > def profile_handler(sender, **kwargs):
> >        """ Signal handler to deal with a save on the User model """
> >        try:
> >                sender.userprofile
> >        except:
> >                profile = cc.models.UserProfile()
> >                profile.user = sender
> >                profile.save()
> >
> > post_save.connect(profile_handler, sender=User)
> >
> > But, what i can't tell is if anything is happening.  If I create a new
> > user and then try userinstance.userprofile, I get the expected
> > exception.
> >
> > Could someone please point me at my issue?
> >
> > Thanks,
> > Jeremiah
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "Django users" group.
> > To post to this group, send email to django-users@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.
> >
> >
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.

Reply via email to