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.c
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://
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
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
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.dr
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'
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
> "wo
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 Tues
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 .
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=1
10 matches
Mail list logo