Re: Need Help with ForeignKeys

2012-05-23 Thread Mark Phillips
Thanks! I think I understand it now! Mark On Wed, May 23, 2012 at 8:00 AM, Simone Federici wrote: > On Wed, May 23, 2012 at 4:40 PM, Mark Phillips > wrote: > >> Now, can you please explain why it worked? What does the related_name do >> and why do I need it? > > When you define a ForeignKey, dj

Re: Need Help with ForeignKeys

2012-05-23 Thread Simone Federici
On Wed, May 23, 2012 at 4:40 PM, Mark Phillips wrote: > Now, can you please explain why it worked? What does the related_name do > and why do I need it? When you define a ForeignKey, django creates dinamically a reverse relationship. take this example: A B.a -> A from an instance of b = B() yo

Re: Need Help with ForeignKeys

2012-05-23 Thread Kurtis Mullins
The related name, basically, specifies a way to back-reference that particular Team. If you don't specify it, it just uses an automatically generated variable name (for example, just 'team'). You'd have a conflict because there'd be two 'team' variables generated in your game class. The method Simo

Re: Need Help with ForeignKeys

2012-05-23 Thread Mark Phillips
Thanks, that worked. Now, can you please explain why it worked? What does the related_name do and why do I need it? Thanks! Mark On Wed, May 23, 2012 at 7:34 AM, Simone Federici wrote: > class Game(models.Model): > game_id = models.IntegerField(primary_key=True) > gamedate = models.Dat

Re: Need Help with ForeignKeys

2012-05-23 Thread Simone Federici
class Game(models.Model): game_id = models.IntegerField(primary_key=True) gamedate = models.DateField() gamestart = models.TimetField(blank=True) duration = models.IntegerField() innings = models.IntegerField() hometeam = models.ForeignKey(Team, related_name='homegame_set')

Need Help with ForeignKeys

2012-05-23 Thread Mark Phillips
I have two tables - Team and Game. class Team(models.Model): team_id = models.IntegerField(primary_key=True) teamname = models.CharField(max_length=255) division_id = models.ForeignKey(Division) class Game(models.Model): game_id = models.IntegerField(primary_key=True) gamedate

Re: help with foreignkeys

2012-05-14 Thread psychok7
thanks thats exactly wht i needed ;) On Monday, May 14, 2012 6:58:47 AM UTC+1, Nikolas Stevenson-Molnar wrote: > > When you have a FK to park in your comment model, you automatically get a > reference to a list of comments from the park model. E.g: > > class Park(models.Model): > #Park fields her

Re: help with foreignkeys

2012-05-13 Thread Nikolas Stevenson-Molnar
When you have a FK to park in your comment model, you automatically get a reference to a list of comments from the park model. E.g: class Park(models.Model): #Park fields here, but no explicit relationship to Comment class Comment(models.Model): park = models.ForeignKey(Park)

Re: help with foreignkeys

2012-05-13 Thread psychok7
i think you are right :) , i can always get the parks associated comments if i query comments model (im used to only doing it the other way around). gonna try that out thanks On Monday, May 14, 2012 2:57:17 AM UTC+1, jondykeman wrote: > > If all comment have to have a park and user. > > I woul

Re: help with foreignkeys

2012-05-13 Thread jondykeman
If all comment have to have a park and user. I would have a ForeignKey to Park and User in the Comments model, and no Foreign key in the Parks model. As such a comment will always need to be linked to an existing park and user object, but a park can be created without needing a comment. JD O

Re: help with foreignkeys

2012-05-13 Thread psychok7
yes, like a park doesn't have to have comments, but all the comments must have an associated park and user all the time. what is the django syntax for me to achieve this? On Monday, May 14, 2012 2:49:18 AM UTC+1, jondykeman wrote: > > As far as I understand it the ForeignKey will have to be uniq

Re: help with foreignkeys

2012-05-13 Thread jondykeman
As far as I understand it the ForeignKey will have to be unique=True and null=False. I want to get a better sense of what you are trying to achieve. Is it that you want to link comment and park only some of the time? JD On Sunday, May 13, 2012 7:41:39 PM UTC-6, psychok7 wrote: > > so i have th

help with foreignkeys

2012-05-13 Thread psychok7
so i have this 2 models (Comment and Park) Comment has a foreign key to USER and PARK PARK has a foreign key to Comment my question is, isn't there going to be a deadlock if i don't have a comment or a park created? i mean , in order to create a Park i need to have a comment, and in order to c