Re: Database Model Layout Advice
On Jul 14, 2009, at 10:35 AM, Jonathan Buchanan wrote: > > One option would be to use a generic relation: > > http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1 > > Regards, > Jonathan. > > Yes, this is probably the right way to do it. I had heard about generic relation, but forgot. Shawn --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Database Model Layout Advice
2009/7/14 The Danny Bos: > > Hey there, this may not be appropriate, but I'm building in Django so > here goes ... > > I'm creating an Interviews app/table in my Django 'Books' (test) > project. Just wrapping my head around it before I start on my music > based website ... Anyway, > > For my 'Interview' table, how would I assign an interview to an > 'Author' or an 'Illustrator', as they both have separate tables > themselves. Know what I mean? Seems crazy to choose either the Author > from the list OR the Illustrator, how would I assign an Interview to > either? > > Here's the layout for 'Interview': > > class Interview(models.Model): > body = models.TextField() > publication_date = models.DateField(auto_now=True) > > author = models.ForeignKey('books.Author') > illustrator = models.ForeignKey('books.Illustrator') > > class Meta: > ordering = ['publication_date'] One option would be to use a generic relation: http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1 Regards, Jonathan. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Database Model Layout Advice
On Jul 14, 2009, at 9:23 AM, The Danny Bos wrote: > > > So the Author and Illustrator tables would stay as is. > How would the Interview table talk to both of those tables at once, to > allow me to assign an interview to who I'm interviewing. Whether it's > an Illustrator, Author or even down the track a Publisher. > > Like so? > > class Interview(models.Model): >body = models.TextField() >publication_date = models.DateField(auto_now=True) > >interview_subject = ... > >class Meta: >ordering = ['publication_date'] > > No, the other way around. The interview table wouldn't have anything in it to point to the illustrator or author. The Author and Illustrator models would each have a ManyToMany field defined to the Interview model. The "related_name" property of this field will give you an easy way, when using an Interview model, to pull its related Author or Illustrator objects. When you start with an Interview object, you'll need to do something like check to see if: len(this_interview.author.all()) > 0 Shawn --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Database Model Layout Advice
So the Author and Illustrator tables would stay as is. How would the Interview table talk to both of those tables at once, to allow me to assign an interview to who I'm interviewing. Whether it's an Illustrator, Author or even down the track a Publisher. Like so? class Interview(models.Model): body = models.TextField() publication_date = models.DateField(auto_now=True) interview_subject = ... class Meta: ordering = ['publication_date'] On Jul 14, 11:19 pm, Shawn Milochikwrote: > I think you'd just have the interview table without any foreign keys, > then add a ManyToMany to each of your Author and Illustrator models. > > You would still, of course, be able to start with your interview table > and get the authors or illustrators, if necessary in your app. It > might be handy to set the related_name property of this field for easy > reference from your Interview model. > > Shawn --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Database Model Layout Advice
I think you'd just have the interview table without any foreign keys, then add a ManyToMany to each of your Author and Illustrator models. You would still, of course, be able to start with your interview table and get the authors or illustrators, if necessary in your app. It might be handy to set the related_name property of this field for easy reference from your Interview model. Shawn --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Database Model Layout Advice
Hey there, this may not be appropriate, but I'm building in Django so here goes ... I'm creating an Interviews app/table in my Django 'Books' (test) project. Just wrapping my head around it before I start on my music based website ... Anyway, For my 'Interview' table, how would I assign an interview to an 'Author' or an 'Illustrator', as they both have separate tables themselves. Know what I mean? Seems crazy to choose either the Author from the list OR the Illustrator, how would I assign an Interview to either? Here's the layout for 'Interview': class Interview(models.Model): body = models.TextField() publication_date = models.DateField(auto_now=True) author = models.ForeignKey('books.Author') illustrator = models.ForeignKey('books.Illustrator') class Meta: ordering = ['publication_date'] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---