I am trying to design a database structure for a website that offers people to open a personal profile.
I am trying to figure out if the design that I’ve chosen is good enough.. The reason i suspect it might be problematic is that I use many relations between many tables. That way, when a person’s page is being loaded, there are many JOINs behind the scenes and that will surely create a bottleneck. I would appreciate if you can help me figuring out if the design is proper or if I should reconsider it.
So I have come up with the following design:
class Person(models.Model):
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
name = models.CharField(max_length=200)
# Each person can have one profession
profession = models.ForeignKey(Profession)
email = models.CharField(max_length=100, blank=True)
website = models.CharField(max_length=200, blank=True)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES))
birth_date = models.DateField(blank=True, null=True)
class Profession(models.Model):
type = models.CharField(max_length=20, blank=False, choices = ("Teacher","Pilot","Politician"))
#Each person can have several geolocations (represent the person's home/office/other address)
class Geolocation(models.Model):
latitude = models.FloatField()
longitude = models.FloatField()
address = models.TextField()
related_person = models.ForeignKey(Person, blank=False, null=False)
#Each person can have several medias (you tube movies)
class Media(models.Model):
youtube_id = models.CharField(max_length=100)
related_person = models.ForeignKey(Person, blank=False, null=False)
#Each person can have several websites
class Websites(models.Model):
website_url = models.CharField(max_length=200, blank=False)
website_name = models.CharField(max_length=200)
related_person = models.ForeignKey(Person, blank=False, null=False)
#See below...
related_link_farm = models.ForeignKey(LinkFarms, blank=True, null=True)
#Each website that refers to a person must be also refered to a link farm
class LinkFarms(models.Model):
farm_name = models.CharField(max_length=200, blank=False)
Notice that for each page loaded there are at least 5 table joins.
Thanks,
Meir
It’s ok to normalise data. That’s what relational databases are for! Your design looks fine to me. If it becomes a problem you can always cache page renders.