Tuesday, April 16, 2019

Re: compute model field by related field

Implement rest framework

On Tue, Apr 16, 2019, 9:20 PM omar ahmed <omarkadytt@gmail.com> 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+unsubscribe@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+unsubscribe@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.

No comments:

Post a Comment