I am thinking about how to split my website into smaller reusable apps. I've finally figured out something and need your opinion.
My main problem was that each app uses
Profile model. This is of course a snippet of my work with the most important parts.
# App Userdata class BaseProfile(models.Model): city = models.CharField(max_length=100, null=True, blank=True) user = models.OneToOneField(User) class Photo(models.Model): profile = models.ForeignKey(BaseProfile) url = models.URLField() # App Social Connect class SocialConnectProfile(models.Model): pass class SocialConnect(models.Model): profile = models.ForeignKey(SocialConnectProfile) # App Forum class ForumProfile(models.Model): pass class Question(models.Model): profile = models.ForeignKey(ForumProfile) class Answer(models.Model): profile = models.ForeignKey(ForumProfile) question = models.ForeignKey(ForumProfile) # App Base class Profile(BaseProfile, SocialConnectProfile, ForumProfile): pass
What I am worrying about is that there are 5 tables with a one-to-one relationship. What do you think? Are there any better options?
Yes, the code has been pretty much simplified. Each app has many models indeed. (
My target is to extract them as Python-Django components in future, but I haven't done it before.
I want to project them in this way now to save time in future with new applications or extending existing one, but I am not sure if it's the best approach.