It can have embedded classes (a common case is class Meta
), but any models.*Field
members are ignored. It doesn't make sense in SQL.
What you want is a many-to-one:
class Thing(models.Model): # Don't name this class 'Model'!
name = models.CharField(max_length=100)
class ContactDetails:
parent = models.ForeignKey(Thing, related_name="contactDetails")
phone = models.IntegerField()
Then, to access:
thing = Thing();
# ... set up thing ...
thing.save()
contact1 = ContactDetails(parent=thing)
# ... set up contact1 ...
contact1.save()
contact2 = ContactDetails(parent=thing)
# ... set up contact2 ...
contact2.save()
# ...
thing.contactDetails.all()
# returns a list with contact1 and contact2
or whatever.