To answer your question, you could add an extra field on schedule model to
store the winner
e.g. winner = models.CharField(max_length=55)

IMO, league and team in the schedule model should be separate tables. You
would use fk to them in schedule model.
winner should also be an fk to team.


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Tue, May 5, 2020 at 3:54 AM J.T. <jrturner0...@gmail.com> wrote:

> I'm working on an app that will allow the user to select the winner
> between two teams (radio buttons) and I need the info saved to the
> database. I'm having trouble with the radio forms part. I've read the
> documentation and searched Google all day, but I can't seem to wrap my
> heads around it.
>
> Here are my models:
>
> class Schedule(models.Model):
>     LEAGUE_CHOICES = (('HS','HS'), ('NFL', 'NFL'), ('NCAA','NCAA'))
>     week = models.IntegerField()
>     game_id = models.IntegerField(unique=True)
>     away_team = models.CharField(max_length=55)
>     home_team = models.CharField(max_length=55)
>     away_id = models.IntegerField(unique=True)
>     home_id = models.IntegerField(unique=True)
>     league = models.CharField(max_length=15, choices=LEAGUE_CHOICES)
>     def __str__(self):
>         return f'Week {self.week} {self.away_team} vs {self.home_team}'
>
> class Selection(models.Model):
>     username = models.ForeignKey(User, on_delete=models.CASCADE)
>     week = models.ForeignKey(Schedule, on_delete=models.CASCADE)
>     select_one = models.CharField(max_length=50)
>     select_two = models.CharField(max_length=50)
>     select_three = models.CharField(max_length=50)
>     select_four = models.CharField(max_length=50)
>     select_five = models.CharField(max_length=50)
>     select_six = models.CharField(max_length=50)
>     select_seven = models.CharField(max_length=50)
>     select_eight = models.CharField(max_length=50)
>     select_nine = models.CharField(max_length=50)
>     select_ten = models.CharField(max_length=50)
>     tie_breaker = models.IntegerField()
>     def __str__(self):
>         return f'Week {self.week} selections for {self.username}'
>
> Below is a portion of what I want the template to look like when rendered.
> It takes the teams from the "Schedule" model
> and displays them.
> I then want the id of the selection (the value) of each game saved to the
> "Selections" model (select_one, select_two, etc.)
> I can't figure out how to tie in the view so it saves the data to the db.
> I realize I need to create a forms.py, import it into the view, but that
> is the part I'm having trouble understanding. I don't
> know what my forms.py should look like since the team names will change
> weekly and each match-up is it's own radio selection.
> Any help is greatly appreciated. Also, if I'm screwing this up on the
> models level, let me know. I realize that could
> also be an issue.
> JT
>
> 1  Oklahoma  Oklahoma State NCAA
> 1  Texas Christian  Houston NCAA
> 1  Dallas  Philadelphia NFL
> 1  Houston  Indianapolis NFL
> 1  New Orleans  Atlanta NFL
>
>
>
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/398cb0ad-fb81-49ff-bbee-53aa054b6a17%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/398cb0ad-fb81-49ff-bbee-53aa054b6a17%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMKMUjt7dG6QL_WRzB43H%2Bc4f%2B1Gkgt7PSb5YZLd_8Lde4OD-w%40mail.gmail.com.

Reply via email to