This is a many to many relation. One contact can have multiple relations, according to your text, but clearly, more than one contact can be family, etc.
And if, instead, each contact can have only one relation, then the ForeignKey goes in the Resource (contact) model, not the Relationship (category) model. On Wed, May 11, 2016 at 7:17 AM, Bruce Whealton < futurewavewebdevelopm...@gmail.com> wrote: > Hello all, > I think that my problem here is Django specific and not > necessarily a reflection on > my understanding of relational databases (hopefully). > I did post about this previously and thought I had figured out what to > do. > I have a Django app that stores information on Contacts. > With that one table things seemed to work fine. When I wanted to > categorize > the type of relationship - is this a professional relationship, family, > friends, etc. > That's when things didn't show up like I wanted. I finally got the > migration to work > with the new table. > I'm using python 3 with the latest version of django. I have a > mysql > database. I want a one to many relationship, where one contact can > be characterized by many categories. When I work with the django admin > and try to enter a contact, I'm not seeing a field for entering > relationship categories. > > So, here is my models.py for the contacts app. > > from django.db import models > > > class Resource(models.Model): > first_name = models.CharField(max_length=40) > last_name = models.CharField(max_length=40) > organization = models.CharField(max_length=60, null=True, blank=True) > street_line1 = models.CharField("Street Line 1", max_length=50, > null=True, blank=True) > street_line2 = models.CharField("Street Line 2", max_length=50, > null=True, blank=True) > city = models.CharField(max_length=40, null=True, blank=True) > state = models.CharField(max_length=40, null=True, blank=True) > zipcode = models.CharField(max_length=20, blank=True, null=True) > phone1 = models.CharField(max_length=20, null=True, blank=True) > phone2 = models.CharField(max_length=20, null=True, blank=True) > email = models.EmailField(max_length=60, null=True, blank=True) > website = models.URLField(max_length=90, null=True, blank=True) > > def __str__(self): > return "%s %s \t%s" % (self.first_name, self.last_name, > self.organization) > > class Meta: > ordering = ('last_name',) > > > class Relationship(models.Model): > category = models.CharField(max_length=120) > resource = models.ForeignKey(Resource, related_name='category') > > def __str__(self): > return self.category > > class Meta: > ordering = ('category',) > > Thanks in advance for any help, > Bruce > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/ab683e85-6945-4387-acd2-0ae3357db268%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/ab683e85-6945-4387-acd2-0ae3357db268%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAB%2BAj0uAze_TcNadKxA_yYU7Z2ug%3Dtt_NTH9_W6Za22n8-boYQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.