On 2 mar, 19:31, Jeremiah <wanderinweez...@gmail.com> wrote: (snip) >> Given the above statement, I assume the "models.py" file you're >> talking about is not the one where you define your UserProfile class. (snip)
> It is the same models.py file with the UserProfile class. Is this the > incorrect way to set this up? I have a feeling I'm completely missing > something. If it's in the same module (=> .py file), then you don't have to reference it as "cc.models.UserProfile" - "UserProfile" is enough. IOW: def profile_handler(sender, **kwargs): """ Signal handler to deal with a save on the User model """ try: sender.userprofile except UserProfile.DoesNotExist: profile = UserProfile(user=sender) profile.save() > I have it registered under INSTALLED_APPS using the name of the > project Don't. It's not necessary, and may break if for any reason you either rename your project or try to reuse the same app in another project. Also and FWIW, there are (complicated) issues with modules / packages qualified names and the way django import models at startup, that may end up with your module being imported twice under two different names. The only potential problem with removing the "project" namespace from your settings.INSTALLED_APPS *and* imports is that you'll have to add both the project's parent dir and the project's dir in your sys.path (in the .wsgi file) when deploying using mod_wsgi. > > > FWIW, you can insert print statements (poor man logging) in your > > models.py file to make sure it's imported and check if the signal > > handler is executed: > > > # wherever/models.py > > from django.db.models.signals import post_save > > > print "in %s" % __name__ > > > def profile_handler(sender, **kwargs): > > """ Signal handler to deal with a save on the User model """ > > try: > > p = sender.userprofile > > print "in %s : for user %s, profile %s already exists" % > > (__name__, sender, p) > > except cc.models.UserProfile.DoesNotExist: > > profile = cc.models.UserProfile(user=sender) > > profile.save() > > print "in %s : for user %s, created profile %s " % (__name__, > > sender, p) > > except Exception, e: > > print "in %s : for user %s, got unexpected exception %s" % > > (__name__, sender, e) > > raise > > > print "in %s : connecting profile_handler to post_save signal" % > > __name__ > > post_save.connect(profile_handler, sender=User) > > print "in %s : connected profile_handler to post_save signal" % > > __name__ > > Thanks! I didn't know you could do that - I thought it would be > gobbled up as invalid output by the http server so I hadn't tried. It's invalid when running django behind a front-end webserver like Apache but works fine with the builtin dev server. The RightThingToDo(tm) is of course to use Python's logging package, but it's a bit more involved. > > <OT>While we're at it, the pythonic convention for indentations is 4- > > spaces, no tabs</OT> > > Thank you for this as well! I'm both new to Django and Python - > learning as I go. comp.lang.py is a very newbie-friendly place (well, it's a very friendly place, period), with quite a few gurus hanging around. I strongly suggest you post your "pure-python" questions there. I learned quite a few thangs lurking there ;) -- 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.