Question regarding how to setup dbase relationships (newbie, this may be trivial)
Followed the django tutorial (Poll, Choices); understood that 1 Poll has many Choice(s), therefore many Choice(s) point to a single Poll.
class Poll(models.Model):
question = models.CharField(max_length=200)
...
class Choice(models.Model):
poll = models.ForeignKey(Poll)
...
Question: I have a database with places, persons, etc. (mutiple tables). A subset of my tables have a similar field. I want a place to have 1+ phone_number(s). I want a person to have 1+ phone_number(s). I may want other tables to have 1+ phone_number(s).
If I followed the Poll/Choice approach, then my problem is indicated by the question marks shown below under PhoneNumber.
class Person(models.Model):
firstname = models.CharField(max_length=20)
...
class Place(models.Model):
description = models.CharField(max_length=200)
...
class PhoneNumber(models.Model):
??? = models.ForeignKey(???)
...
I have considered using inheritance so that both Person and Place inherit from the same base class. But I may have other fields besides phone_number for which I have a similar situation, and which span a different subset of tables. E.g.
phone_number(s) comments
--------------- --------
Person yes no
Place yes yes
Contract no yes
...
Any advice on how to correctly design these types of relationships would be greatly appreciated. Thank you.