Re: Help about models
Hello Greg and Jirka, Thanks for the help. I was rereading the tutorial to understand the ForeignKey. It says that ForeignKey "tells Django each Choice is related to a single Poll." In my case, each lawyer is associated with 1 law school; and each law school is associated with 1 or more lawyers. Considering this I thought that ForeignKey should tell Django that "each lawyer is related to a single School" so I put ForeignKey under Lawyer: class Education(models.Model): school = models.CharField(max_length=200) class Lawyer(models.Model): first = models.CharField(max_length=20) initial = models.CharField(max_length=2) last = models.CharField(max_length=20) year_graduated = models.DateTimeField('Year graduated') education = models.ForeignKey(Education) Does this make sense? And, can you explain why this is needed in terms of searching the database? What happens if I don't use a foreign key? Thanks again. On Nov 9, 7:36 am, Jirka Vejrazka wrote: > > I commented out the ForeignKey because it caused an error. > > Just a small coding note - it was causing an error because you did not > specify the model name exactly (compare the character case) > > Jirka --~--~-~--~~~---~--~~ 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: Help about models
> I commented out the ForeignKey because it caused an error. Just a small coding note - it was causing an error because you did not specify the model name exactly (compare the character case) Jirka --~--~-~--~~~---~--~~ 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: Help about models
What you need is to keep your Education model as is (with no Lawyer Foreignkey) and add a ManyToManyField on your Lawyer class pointing to Education. Then you can go Lawyer.objects.filter(education__school='...') I think that will solve your problem Greg 2009/11/9 Zeynel : > > Hello, > > I decided to start my own project with what I learned from part 1 of > the tutorial. > > I have the project in C:\sw\sw\wkw > > The app sw.wkw is a prototype for a "who-knows-who" database for legal > profession. I wanted to start with a really simple model: > > class Lawyer(models.Model): > first = models.CharField(max_length=20) > initial = models.CharField(max_length=2) > last = models.CharField(max_length=20) > year_graduated = models.DateTimeField('Year graduated') > > class Education(models.Model): > # lawyer = models.ForeignKey(lawyer) > school = models.CharField(max_length=200) > > I commented out the ForeignKey because it caused an error. > > I will only make one search in the database. I want to enter Lawyer's > name and find all other lawyers in the database who graduated from the > same school the same year. It's like sorting by school in a > spreadsheet and pulling the lawyer's names. Here's the sample > spreadsheet: > > https://spreadsheets.google.com/ccc?key=0Al923jWh4O4ydG1vSmx4bDVqTUFUXzVqSXhzVkcydmc&hl=en > > Do you think this is the right model for what I am trying to do? Thank > you for your comments. > > So far I created the tables and tomorrow I'll set up the admin and > populate the database with some names. > > I am really enjoying Django. I am learning both Django and Python. > Thanks again for your help. > > > -- http://gregbrown.co.nz/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---