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
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
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
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
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')
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
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
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)
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
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
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
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
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
13 matches
Mail list logo