Skip to content

Instantly share code, notes, and snippets.

@Hippocrates
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hippocrates/16db9eb2ee6de40d1c2b to your computer and use it in GitHub Desktop.
Save Hippocrates/16db9eb2ee6de40d1c2b to your computer and use it in GitHub Desktop.
This was supposed to be in a datamigration at some point
from tracker.models import *;
def run():
tickets = list(PrizeTicket.objects.all())
for ticket in tickets:
if( PrizeTicket.objects.filter(pk=ticket.pk).exists() ):
equivalents = list(filter(lambda x: x != ticket, PrizeTicket.objects.filter(donation=ticket.donation,prize=ticket.prize)))
if len(equivalents) > 0:
for x in equivalents:
ticket.amount += x.amount;
x.delete()
ticket.save()
bids = list(DonationBid.objects.all())
for donationbid in bids:
if( DonationBid.objects.filter(pk=donationbid.pk).exists() ):
equivalents = list(filter(lambda x: x != donationbid, DonationBid.objects.filter(donation=donationbid.donation,bid=donationbid.bid)))
if len(equivalents) > 0:
for x in equivalents:
donationbid.amount += x.amount;
x.delete()
donationbid.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment