On Nov 8, 2007 7:41 AM, Alexander Solovyov <[EMAIL PROTECTED]> wrote: > > On Nov 8, 2007 2:21 PM, Jonathan Buchanan <[EMAIL PROTECTED]> wrote: > > On this particular point, from the perspective of the reusable > > applications themselves, you don't need to worry about merging profile > > models, even if you are potentially working with many of them in your > > overall project. Going with the forum example, if your forum > > application defines its own profile Model which addresses all of its > > specific needs, it doesn't benefit it in any way if it has access to > > some kind of merged profile instead - it does, however, introduce the > > potential for conflicts. > > > > Personally, I never rely on the AUTH_PROFILE_MODEL setting and the > > User.get_profile method in reusable applications, I only use those in > > my main project. It's not a lot of work to add a method to your > > application's profile Manager to load and cache a user's > > application-specific profile in a manner similar to User.get_profile. > > Since I'm actually working on a reusable forum application at the > > moment, here's an example of what I mean: > > But what about if your forum have a field for an Jabber account or ICQ UIN > and a blog (whatever) application has the same? Synchronize them using > signals? > Isn't this not very safe solution? > > -- > Alexander
If the applications had no knowledge of each other, I would consider some quick and dirty hack using signals to keep them synchronised, yes. :) I would prefer to write some generic, reusable code to do this of course, but just off the top of my head I can't think of a nice way - you'd have to encapsulate knowledge of how to obtain one type of profile object for the same user given another one of their profile objects and deal with things like different profile models having different names for the same fields (who's to say the authors of any particular application will agree with the field naming choices of any other?) or even different field definitions for the same data. Here's some inelegantly shuffled together code which might solve the example problem given, in which I've purposefully made the model details awkwardly incompatible to demonstrate some of the issues you would have to deal with :) from django.db.models import signals from django.dispatch import dispatcher from blog.models import BlogProfile from forum.models import ForumProfile def sync_blog_profile(sender, instance, signal, *args,**kwargs): blog_profile = BlogProfile.objects.for_user(instance.forum_user) needs_save = False if blog_profile.icq_number != instance.icq_num: blog_profile.icq_number = instance.icq_num needs_save = True if blog_profile.jabber != instance.jabber_account: blog_profile.jabber= instance.jabber_account needs_save = True if needs_save: blog_profile.save() def sync_forum_profile(sender, instance, signal, *args,**kwargs): forum_profile = ForumProfile.objects.get_for_user(instance.user) needs_save = False if forum_profile.icq_num != instance.icq_number: forum_profile.icq_num = instance.icq_number needs_save = True if forum_profile.jabber_account != instance.jabber: forum_profile.jabber_account = instance.jabber needs_save = True if needs_save: forum_profile.save() dispatcher.connect(sync_blog_profile, signal=signals.post_save, sender=ForumProfile) dispatcher.connect(sync_forum_profile, signal=signals.post_save, sender=BlogProfile) Jonathan. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---