Re: compute model field by related field

2019-04-24 Thread omar ahmed
ok Derek i used save() instead of return and it works now 
thank you very much 
@receiver(post_save, sender=Match)
def update_club_score(instance, sender, **kwargs):
# club local won
if instance.score_local > instance.score_visitor:
instance.club_local.won += 1
instance.club_local.save()
instance.club_visitor.lost += 1
instance.club_visitor.save()
# club local lost
if instance.score_local < instance.score_visitor:
instance.club_local.lost += 1
instance.club_local.save()
instance.club_visitor.won += 1
instance.club_visitor.save()
# draw
if instance.score_local == instance.score_visitor:
instance.club_local.draw += 1
instance.club_local.save()
instance.club_visitor.draw += 1
instance.club_visitor.save()


On Wednesday, April 24, 2019 at 8:13:05 AM UTC+2, Derek wrote:
>
> Did you add the required decorator before this function?  (The function is 
> not part of the class; its a standalone appearing in the same module.)
>
> Also, you generally don't put returns in the post_save function: but you 
> do need to call save() on the model instance.
>
> Another example here:
>
> https://stackoverflow.com/questions/13014411/django-post-save-signal-implementation
>
> On Tuesday, 23 April 2019 16:31:43 UTC+2, omar ahmed wrote:
>>
>> yes i studied this tutorial before and i added this function to "Club" 
>> class (( Receiver function class )) but it does not affect fields 
>> def teampoints( sender, instance, **kwargs):
>> if instance.score_local > instance.score_visitor:
>> return instance.club_local.won +1 and instance.club_visitor.lost + 1
>> elif instance.score_local < instance.score_visitor:
>> return instance.club_local.lost + 1 and instance.club_visitor.won + 1
>> else:
>> return instance.club_local.draw + 1 and instance.club_visitor.draw + 1
>>
>>
>> On Tuesday, April 23, 2019 at 3:27:28 PM UTC+2, Derek wrote:
>>>
>>> You need to use Django signals to provide a custom "post_save".  There 
>>> is a good tutorial here:
>>>
>>> https://simpleisbetterthancomplex.com/tutorial/2016/07/28/how-to-create-django-signals.html
>>>
>>>
>>> On Monday, 22 April 2019 16:22:19 UTC+2, omar ahmed wrote:

 i put this function in "Match" class :
 def points(self):
 if self.score_local > self.score_visitor:
 return (self.club_local.won)+1 and (self.club_visitor.lost)+1
 elif self.score_local < self.score_visitor:
 return (self.club_local.lost)+1 and (self.club_visitor.won)+1
 else:
 return (self.club_local.draw)+1 and (self.club_visitor.draw)+1
 and i want it to update fields and 'CalcPoints' function in "Club" 
 class 
 class Club(models.Model):
 ...
 def CalcPoints(self):
 return self.won*3 + self.draw

 but until now it does not update objects (( how can i use post_save 
 here )) 

 On Saturday, April 20, 2019 at 9:09:01 AM UTC+2, Derek wrote:
>
> That should just require a basic if/then logic test; "get" the correct 
> Club object, update the win/loss field and save the Club. Repeat for both 
> Clubs.
>
> On Thursday, 18 April 2019 14:09:41 UTC+2, omar ahmed wrote:
>>
>> thank you for response , derek
>> but how can i increment 'win' 'lost' or 'draw' Club fields by 
>> 'winner' Match field
>>
>> On Wednesday, April 17, 2019 at 3:26:22 PM UTC+2, Derek wrote:
>>>
>>> 1. Add a "winner" field to your Match
>>> 2. Implement a post_save  signal for the Match model that updates 
>>> the "won" or "lost" fields for each Club in the match (simple if/then 
>>> logic 
>>> based on winner).
>>>
>>> PS I think the default values for "won" and "lost" for a Club should 
>>> be "0" and not "1".
>>>
>>> On Tuesday, 16 April 2019 20:19:34 UTC+2, omar ahmed wrote:

 hello ... i have two models "Club" class and "Match" class and it 
 has foreign key to Club
 now i want to increment "won" field (or draw or lost) in "Club" 
 class by "score_local" and "score_visitor" in "Match" class ..
 how can i do this
 class Club(models.Model):
 name = models.CharField(max_length=100)
 won = models.IntegerField(default=1)
 draw = models.IntegerField(default=1)
 lost = models.IntegerField()
 goal_for = models.IntegerField()
 goal_against = models.IntegerField()


 class Match(models.Model):
 play_date = models.DateTimeField('play date')
 club_visitor = models.ForeignKey(Club, on_delete=models.CASCADE, 
 related_name='match_club_visitor')
 club_local = models.ForeignKey(Club, on_delete=models.CASCADE, 
 related_name='match_club_local')
 score_visitor = models.IntegerField()
 score_local = models.IntegerField()

>>>

-- 
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 

Re: compute model field by related field

2019-04-24 Thread Derek
Did you add the required decorator before this function?  (The function is 
not part of the class; its a standalone appearing in the same module.)

Also, you generally don't put returns in the post_save function: but you do 
need to call save() on the model instance.

Another example here:
https://stackoverflow.com/questions/13014411/django-post-save-signal-implementation

On Tuesday, 23 April 2019 16:31:43 UTC+2, omar ahmed wrote:
>
> yes i studied this tutorial before and i added this function to "Club" 
> class (( Receiver function class )) but it does not affect fields 
> def teampoints( sender, instance, **kwargs):
> if instance.score_local > instance.score_visitor:
> return instance.club_local.won +1 and instance.club_visitor.lost + 1
> elif instance.score_local < instance.score_visitor:
> return instance.club_local.lost + 1 and instance.club_visitor.won + 1
> else:
> return instance.club_local.draw + 1 and instance.club_visitor.draw + 1
>
>
> On Tuesday, April 23, 2019 at 3:27:28 PM UTC+2, Derek wrote:
>>
>> You need to use Django signals to provide a custom "post_save".  There is 
>> a good tutorial here:
>>
>> https://simpleisbetterthancomplex.com/tutorial/2016/07/28/how-to-create-django-signals.html
>>
>>
>> On Monday, 22 April 2019 16:22:19 UTC+2, omar ahmed wrote:
>>>
>>> i put this function in "Match" class :
>>> def points(self):
>>> if self.score_local > self.score_visitor:
>>> return (self.club_local.won)+1 and (self.club_visitor.lost)+1
>>> elif self.score_local < self.score_visitor:
>>> return (self.club_local.lost)+1 and (self.club_visitor.won)+1
>>> else:
>>> return (self.club_local.draw)+1 and (self.club_visitor.draw)+1
>>> and i want it to update fields and 'CalcPoints' function in "Club" class 
>>> class Club(models.Model):
>>> ...
>>> def CalcPoints(self):
>>> return self.won*3 + self.draw
>>>
>>> but until now it does not update objects (( how can i use post_save here 
>>> )) 
>>>
>>> On Saturday, April 20, 2019 at 9:09:01 AM UTC+2, Derek wrote:

 That should just require a basic if/then logic test; "get" the correct 
 Club object, update the win/loss field and save the Club. Repeat for both 
 Clubs.

 On Thursday, 18 April 2019 14:09:41 UTC+2, omar ahmed wrote:
>
> thank you for response , derek
> but how can i increment 'win' 'lost' or 'draw' Club fields by 'winner' 
> Match field
>
> On Wednesday, April 17, 2019 at 3:26:22 PM UTC+2, Derek wrote:
>>
>> 1. Add a "winner" field to your Match
>> 2. Implement a post_save  signal for the Match model that updates the 
>> "won" or "lost" fields for each Club in the match (simple if/then logic 
>> based on winner).
>>
>> PS I think the default values for "won" and "lost" for a Club should 
>> be "0" and not "1".
>>
>> On Tuesday, 16 April 2019 20:19:34 UTC+2, omar ahmed wrote:
>>>
>>> hello ... i have two models "Club" class and "Match" class and it 
>>> has foreign key to Club
>>> now i want to increment "won" field (or draw or lost) in "Club" 
>>> class by "score_local" and "score_visitor" in "Match" class ..
>>> how can i do this
>>> class Club(models.Model):
>>> name = models.CharField(max_length=100)
>>> won = models.IntegerField(default=1)
>>> draw = models.IntegerField(default=1)
>>> lost = models.IntegerField()
>>> goal_for = models.IntegerField()
>>> goal_against = models.IntegerField()
>>>
>>>
>>> class Match(models.Model):
>>> play_date = models.DateTimeField('play date')
>>> club_visitor = models.ForeignKey(Club, on_delete=models.CASCADE, 
>>> related_name='match_club_visitor')
>>> club_local = models.ForeignKey(Club, on_delete=models.CASCADE, 
>>> related_name='match_club_local')
>>> score_visitor = models.IntegerField()
>>> score_local = models.IntegerField()
>>>
>>

-- 
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/432af72e-69f0-4f17-8e08-a748733fe8e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: compute model field by related field

2019-04-23 Thread omar ahmed
yes i studied this tutorial before and i added this function to "Club" 
class (( Receiver function class )) but it does not affect fields 
def teampoints( sender, instance, **kwargs):
if instance.score_local > instance.score_visitor:
return instance.club_local.won +1 and instance.club_visitor.lost + 1
elif instance.score_local < instance.score_visitor:
return instance.club_local.lost + 1 and instance.club_visitor.won + 1
else:
return instance.club_local.draw + 1 and instance.club_visitor.draw + 1


On Tuesday, April 23, 2019 at 3:27:28 PM UTC+2, Derek wrote:
>
> You need to use Django signals to provide a custom "post_save".  There is 
> a good tutorial here:
>
> https://simpleisbetterthancomplex.com/tutorial/2016/07/28/how-to-create-django-signals.html
>
>
> On Monday, 22 April 2019 16:22:19 UTC+2, omar ahmed wrote:
>>
>> i put this function in "Match" class :
>> def points(self):
>> if self.score_local > self.score_visitor:
>> return (self.club_local.won)+1 and (self.club_visitor.lost)+1
>> elif self.score_local < self.score_visitor:
>> return (self.club_local.lost)+1 and (self.club_visitor.won)+1
>> else:
>> return (self.club_local.draw)+1 and (self.club_visitor.draw)+1
>> and i want it to update fields and 'CalcPoints' function in "Club" class 
>> class Club(models.Model):
>> ...
>> def CalcPoints(self):
>> return self.won*3 + self.draw
>>
>> but until now it does not update objects (( how can i use post_save here 
>> )) 
>>
>> On Saturday, April 20, 2019 at 9:09:01 AM UTC+2, Derek wrote:
>>>
>>> That should just require a basic if/then logic test; "get" the correct 
>>> Club object, update the win/loss field and save the Club. Repeat for both 
>>> Clubs.
>>>
>>> On Thursday, 18 April 2019 14:09:41 UTC+2, omar ahmed wrote:

 thank you for response , derek
 but how can i increment 'win' 'lost' or 'draw' Club fields by 'winner' 
 Match field

 On Wednesday, April 17, 2019 at 3:26:22 PM UTC+2, Derek wrote:
>
> 1. Add a "winner" field to your Match
> 2. Implement a post_save  signal for the Match model that updates the 
> "won" or "lost" fields for each Club in the match (simple if/then logic 
> based on winner).
>
> PS I think the default values for "won" and "lost" for a Club should 
> be "0" and not "1".
>
> On Tuesday, 16 April 2019 20:19:34 UTC+2, omar ahmed wrote:
>>
>> hello ... i have two models "Club" class and "Match" class and it has 
>> foreign key to Club
>> now i want to increment "won" field (or draw or lost) in "Club" class 
>> by "score_local" and "score_visitor" in "Match" class ..
>> how can i do this
>> class Club(models.Model):
>> name = models.CharField(max_length=100)
>> won = models.IntegerField(default=1)
>> draw = models.IntegerField(default=1)
>> lost = models.IntegerField()
>> goal_for = models.IntegerField()
>> goal_against = models.IntegerField()
>>
>>
>> class Match(models.Model):
>> play_date = models.DateTimeField('play date')
>> club_visitor = models.ForeignKey(Club, on_delete=models.CASCADE, 
>> related_name='match_club_visitor')
>> club_local = models.ForeignKey(Club, on_delete=models.CASCADE, 
>> related_name='match_club_local')
>> score_visitor = models.IntegerField()
>> score_local = models.IntegerField()
>>
>

-- 
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/292b1f7f-d360-4db8-8605-1a9647df6600%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: compute model field by related field

2019-04-23 Thread Derek
You need to use Django signals to provide a custom "post_save".  There is a 
good tutorial here:
https://simpleisbetterthancomplex.com/tutorial/2016/07/28/how-to-create-django-signals.html


On Monday, 22 April 2019 16:22:19 UTC+2, omar ahmed wrote:
>
> i put this function in "Match" class :
> def points(self):
> if self.score_local > self.score_visitor:
> return (self.club_local.won)+1 and (self.club_visitor.lost)+1
> elif self.score_local < self.score_visitor:
> return (self.club_local.lost)+1 and (self.club_visitor.won)+1
> else:
> return (self.club_local.draw)+1 and (self.club_visitor.draw)+1
> and i want it to update fields and 'CalcPoints' function in "Club" class 
> class Club(models.Model):
> ...
> def CalcPoints(self):
> return self.won*3 + self.draw
>
> but until now it does not update objects (( how can i use post_save here 
> )) 
>
> On Saturday, April 20, 2019 at 9:09:01 AM UTC+2, Derek wrote:
>>
>> That should just require a basic if/then logic test; "get" the correct 
>> Club object, update the win/loss field and save the Club. Repeat for both 
>> Clubs.
>>
>> On Thursday, 18 April 2019 14:09:41 UTC+2, omar ahmed wrote:
>>>
>>> thank you for response , derek
>>> but how can i increment 'win' 'lost' or 'draw' Club fields by 'winner' 
>>> Match field
>>>
>>> On Wednesday, April 17, 2019 at 3:26:22 PM UTC+2, Derek wrote:

 1. Add a "winner" field to your Match
 2. Implement a post_save  signal for the Match model that updates the 
 "won" or "lost" fields for each Club in the match (simple if/then logic 
 based on winner).

 PS I think the default values for "won" and "lost" for a Club should be 
 "0" and not "1".

 On Tuesday, 16 April 2019 20:19:34 UTC+2, omar ahmed wrote:
>
> hello ... i have two models "Club" class and "Match" class and it has 
> foreign key to Club
> now i want to increment "won" field (or draw or lost) in "Club" class 
> by "score_local" and "score_visitor" in "Match" class ..
> how can i do this
> class Club(models.Model):
> name = models.CharField(max_length=100)
> won = models.IntegerField(default=1)
> draw = models.IntegerField(default=1)
> lost = models.IntegerField()
> goal_for = models.IntegerField()
> goal_against = models.IntegerField()
>
>
> class Match(models.Model):
> play_date = models.DateTimeField('play date')
> club_visitor = models.ForeignKey(Club, on_delete=models.CASCADE, 
> related_name='match_club_visitor')
> club_local = models.ForeignKey(Club, on_delete=models.CASCADE, 
> related_name='match_club_local')
> score_visitor = models.IntegerField()
> score_local = models.IntegerField()
>


-- 
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/cdf83be9-5f8d-4bf8-bd5d-939599e08726%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: compute model field by related field

2019-04-22 Thread omar ahmed
i put this function in "Match" class :
def points(self):
if self.score_local > self.score_visitor:
return (self.club_local.won)+1 and (self.club_visitor.lost)+1
elif self.score_local < self.score_visitor:
return (self.club_local.lost)+1 and (self.club_visitor.won)+1
else:
return (self.club_local.draw)+1 and (self.club_visitor.draw)+1
and i want it to update fields and 'CalcPoints' function in "Club" class 
class Club(models.Model):
...
def CalcPoints(self):
return self.won*3 + self.draw

but until now it does not update objects (( how can i use post_save here )) 

On Saturday, April 20, 2019 at 9:09:01 AM UTC+2, Derek wrote:
>
> That should just require a basic if/then logic test; "get" the correct 
> Club object, update the win/loss field and save the Club. Repeat for both 
> Clubs.
>
> On Thursday, 18 April 2019 14:09:41 UTC+2, omar ahmed wrote:
>>
>> thank you for response , derek
>> but how can i increment 'win' 'lost' or 'draw' Club fields by 'winner' 
>> Match field
>>
>> On Wednesday, April 17, 2019 at 3:26:22 PM UTC+2, Derek wrote:
>>>
>>> 1. Add a "winner" field to your Match
>>> 2. Implement a post_save  signal for the Match model that updates the 
>>> "won" or "lost" fields for each Club in the match (simple if/then logic 
>>> based on winner).
>>>
>>> PS I think the default values for "won" and "lost" for a Club should be 
>>> "0" and not "1".
>>>
>>> On Tuesday, 16 April 2019 20:19:34 UTC+2, omar ahmed wrote:

 hello ... i have two models "Club" class and "Match" class and it has 
 foreign key to Club
 now i want to increment "won" field (or draw or lost) in "Club" class 
 by "score_local" and "score_visitor" in "Match" class ..
 how can i do this
 class Club(models.Model):
 name = models.CharField(max_length=100)
 won = models.IntegerField(default=1)
 draw = models.IntegerField(default=1)
 lost = models.IntegerField()
 goal_for = models.IntegerField()
 goal_against = models.IntegerField()


 class Match(models.Model):
 play_date = models.DateTimeField('play date')
 club_visitor = models.ForeignKey(Club, on_delete=models.CASCADE, 
 related_name='match_club_visitor')
 club_local = models.ForeignKey(Club, on_delete=models.CASCADE, 
 related_name='match_club_local')
 score_visitor = models.IntegerField()
 score_local = models.IntegerField()

>>>

-- 
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/fec08ef3-9ee0-4a3e-98fa-44775e80baba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: compute model field by related field

2019-04-20 Thread Derek
That should just require a basic if/then logic test; "get" the correct Club 
object, update the win/loss field and save the Club. Repeat for both Clubs.

On Thursday, 18 April 2019 14:09:41 UTC+2, omar ahmed wrote:
>
> thank you for response , derek
> but how can i increment 'win' 'lost' or 'draw' Club fields by 'winner' 
> Match field
>
> On Wednesday, April 17, 2019 at 3:26:22 PM UTC+2, Derek wrote:
>>
>> 1. Add a "winner" field to your Match
>> 2. Implement a post_save  signal for the Match model that updates the 
>> "won" or "lost" fields for each Club in the match (simple if/then logic 
>> based on winner).
>>
>> PS I think the default values for "won" and "lost" for a Club should be 
>> "0" and not "1".
>>
>> On Tuesday, 16 April 2019 20:19:34 UTC+2, omar ahmed wrote:
>>>
>>> hello ... i have two models "Club" class and "Match" class and it has 
>>> foreign key to Club
>>> now i want to increment "won" field (or draw or lost) in "Club" class by 
>>> "score_local" and "score_visitor" in "Match" class ..
>>> how can i do this
>>> class Club(models.Model):
>>> name = models.CharField(max_length=100)
>>> won = models.IntegerField(default=1)
>>> draw = models.IntegerField(default=1)
>>> lost = models.IntegerField()
>>> goal_for = models.IntegerField()
>>> goal_against = models.IntegerField()
>>>
>>>
>>> class Match(models.Model):
>>> play_date = models.DateTimeField('play date')
>>> club_visitor = models.ForeignKey(Club, on_delete=models.CASCADE, 
>>> related_name='match_club_visitor')
>>> club_local = models.ForeignKey(Club, on_delete=models.CASCADE, 
>>> related_name='match_club_local')
>>> score_visitor = models.IntegerField()
>>> score_local = models.IntegerField()
>>>
>>

-- 
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/964943b5-1fcb-4324-97bf-3b964af23e36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: compute model field by related field

2019-04-18 Thread omar ahmed
thank you for response , derek
but how can i increment 'win' 'lost' or 'draw' Club fields by 'winner' 
Match field

On Wednesday, April 17, 2019 at 3:26:22 PM UTC+2, Derek wrote:
>
> 1. Add a "winner" field to your Match
> 2. Implement a post_save  signal for the Match model that updates the 
> "won" or "lost" fields for each Club in the match (simple if/then logic 
> based on winner).
>
> PS I think the default values for "won" and "lost" for a Club should be 
> "0" and not "1".
>
> On Tuesday, 16 April 2019 20:19:34 UTC+2, omar ahmed wrote:
>>
>> hello ... i have two models "Club" class and "Match" class and it has 
>> foreign key to Club
>> now i want to increment "won" field (or draw or lost) in "Club" class by 
>> "score_local" and "score_visitor" in "Match" class ..
>> how can i do this
>> class Club(models.Model):
>> name = models.CharField(max_length=100)
>> won = models.IntegerField(default=1)
>> draw = models.IntegerField(default=1)
>> lost = models.IntegerField()
>> goal_for = models.IntegerField()
>> goal_against = models.IntegerField()
>>
>>
>> class Match(models.Model):
>> play_date = models.DateTimeField('play date')
>> club_visitor = models.ForeignKey(Club, on_delete=models.CASCADE, 
>> related_name='match_club_visitor')
>> club_local = models.ForeignKey(Club, on_delete=models.CASCADE, 
>> related_name='match_club_local')
>> score_visitor = models.IntegerField()
>> score_local = models.IntegerField()
>>
>

-- 
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/30a83974-7115-4617-9da2-e32937753cca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: compute model field by related field

2019-04-17 Thread Derek
1. Add a "winner" field to your Match
2. Implement a post_save  signal for the Match model that updates the "won" 
or "lost" fields for each Club in the match (simple if/then logic based on 
winner).

PS I think the default values for "won" and "lost" for a Club should be "0" 
and not "1".

On Tuesday, 16 April 2019 20:19:34 UTC+2, omar ahmed wrote:
>
> hello ... i have two models "Club" class and "Match" class and it has 
> foreign key to Club
> now i want to increment "won" field (or draw or lost) in "Club" class by 
> "score_local" and "score_visitor" in "Match" class ..
> how can i do this
> class Club(models.Model):
> name = models.CharField(max_length=100)
> won = models.IntegerField(default=1)
> draw = models.IntegerField(default=1)
> lost = models.IntegerField()
> goal_for = models.IntegerField()
> goal_against = models.IntegerField()
>
>
> class Match(models.Model):
> play_date = models.DateTimeField('play date')
> club_visitor = models.ForeignKey(Club, on_delete=models.CASCADE, 
> related_name='match_club_visitor')
> club_local = models.ForeignKey(Club, on_delete=models.CASCADE, 
> related_name='match_club_local')
> score_visitor = models.IntegerField()
> score_local = models.IntegerField()
>

-- 
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/d3e8e12a-4b6f-435d-a681-a4a6727bbda0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: compute model field by related field

2019-04-16 Thread Makori Breens
Implement rest framework

On Tue, Apr 16, 2019, 9:20 PM omar ahmed  wrote:

> hello ... i have two models "Club" class and "Match" class and it has
> foreign key to Club
> now i want to increment "won" field (or draw or lost) in "Club" class by
> "score_local" and "score_visitor" in "Match" class ..
> how can i do this
> class Club(models.Model):
> name = models.CharField(max_length=100)
> won = models.IntegerField(default=1)
> draw = models.IntegerField(default=1)
> lost = models.IntegerField()
> goal_for = models.IntegerField()
> goal_against = models.IntegerField()
>
>
> class Match(models.Model):
> play_date = models.DateTimeField('play date')
> club_visitor = models.ForeignKey(Club, on_delete=models.CASCADE,
> related_name='match_club_visitor')
> club_local = models.ForeignKey(Club, on_delete=models.CASCADE,
> related_name='match_club_local')
> score_visitor = models.IntegerField()
> score_local = models.IntegerField()
>
> --
> 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/33e234c0-22d1-43aa-be66-fd2149cd085d%40googlegroups.com
> 
> .
> 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/CAOz9w2Fe_cqxKRiBH-NwS%3Dc%3DhQErnB8thc0_kYcmAkWbZsnBXQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.