1
\$\begingroup\$

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. (BaseProfile has 8, SocialConnect only 1, Forum 18)

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.

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Oct 13, 2013 at 13:33
\$\endgroup\$
3
  • \$\begingroup\$ Why don't you just use BaseProfile? None of your other classes seem to add anything. \$\endgroup\$ Commented Oct 14, 2013 at 1:00
  • \$\begingroup\$ @WinstonEwert I would guess the specifics of the other models have been removed for clarity. \$\endgroup\$ Commented Oct 14, 2013 at 2:02
  • 2
    \$\begingroup\$ @JamesKhoury, perhaps. In that case I think the problem has been simplified past the point of being able to evaluate possible solutions. \$\endgroup\$ Commented Oct 14, 2013 at 2:15

1 Answer 1

2
\$\begingroup\$

It depends really on how you will use those models. For example if you always, always get question object then find the answers that belong to it. there is no point adding profile relation with answers models and keep it to questions only.

If in rare cases (not in loops) you might deal with an answer without getting its question object first, its still ok to do answer.question.profile

answered Jan 27, 2015 at 12:18
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.