I am trying to write an application that credits a user's account when
a bet is paid. I have an admin form with the bet and a TabularInline
list of bet choices (the choices that can be bet on). To resolve a bet
a ModelAdmin is used to set the status of the bet to True (paid) and
the winner field on the winning bet choice to True.

I am having troubles figuring out how to intercept saving from the
admin to do the following:

1) get the old bet status
2) save the bet and bet choices
3) if the bet status changed from False to True, pay the bets (i.e.
get booked bets whose bet field matches the bet id and whose choice
winner field is True and notify the user they won).

I tried overwriting the save function on the Bet model, but this is
called before the bet choice changes are written to the database so I
could not see who the winner is.

Any idea how to solve the problem? It seems like I need to override
some save function (the model? form? formset?) and get the status,
call the super, then process the bets -- but I don't know which
function to override and how to get to to the bet choice data from
there.

thanks,

Len
----------
The models look this:

class Bet(models.Model):
    choice = models.CharField(max_length=200)
    status = False   # False: net not paid yet, True: Paid

class BetChoice(models.Model):
    bet = models.ForeignKey(Bet)
    choice = models.CharField(max_length=200)
    winner = models.BooleanField(default=False)   # True for winning
choice

class BookedBet(models.Model):
    bet = models.ForeignKey(Bet)
    choice = models.ForeignKey(BetChoice)
    user = models.ForeignKey(User)

I also have a ModelAdmin set up as follows:

class ChoiceInline(admin.TabularInline):
    model = BetChoice
    extra = 3

class BetAdmin(admin.ModelAdmin):
    fields = [ 'title','status']
    inlines = [ChoiceInline]

admin.site.register(Bet, BetAdmin)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to