diff --git a/apps/social/models.py b/apps/social/models.py index 05dd7b7d9..0d0d2a041 100644 --- a/apps/social/models.py +++ b/apps/social/models.py @@ -161,6 +161,9 @@ class MSocialProfile(mongo.Document): profile = cls.objects.create(user_id=user_id) profile.save() + if not profile.username: + profile.save() + return profile @property @@ -171,6 +174,8 @@ class MSocialProfile(mongo.Document): return None def save(self, *args, **kwargs): + if not self.username: + self.import_user_fields() if not self.subscription_count: self.count_follows(skip_save=True) if self.bio and len(self.bio) > MSocialProfile.bio.max_length: @@ -433,6 +438,11 @@ class MSocialProfile(mongo.Document): return [u for u in self.follower_user_ids if u != self.user_id] return self.follower_user_ids + def import_user_fields(self): + user = User.objects.get(pk=self.user_id) + self.username = user.username + self.email = user.email + def count_follows(self, skip_save=False): self.subscription_count = UserSubscription.objects.filter(user__pk=self.user_id).count() self.shared_stories_count = MSharedStory.objects.filter(user_id=self.user_id).count()