开发者

django custom formsets?

I have this model layout:

class Game(models.Model):
    game_time = models.DateTimeField(db_index=True)
    home_team = models.ForeignKey(Team, related_name="home_games")
    away_team = models.ForeignKey(Team, related_name="away_games")
    home_score = models.IntegerField(null=True, blank=True)
    away_score = models.IntegerField(null=True, blank=True)
    spread = models.FloatField(null=True, blank=True, help_text="With respect to the home team")
    predictions = models.ManyToManyField(User, through="Prediction")

class Prediction(models.Model):
    user = models.ForeignKey(User)
    game = models.ForeignKey(Game)
    prediction = models.BooleanField(help_text="With respect to the home team")

I want users to be able to log in, and see all the games within a 'week', thus, my first thought was to use a formset. However, when the form is saved, I need to be able to inject the logged in user into the Prediction.

I'm not sure if I should be using a formset, or a custom set of rules and just parse out the form information myself.

The biggest problem I had with model formset was it wasn't able 开发者_开发问答to determine if the record existed or not, and adapt automatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜