I would like to run an update query that spans several realtionships. Is this possible with django? This is what I have tried:
from django.db.models import F
Transaction.objects.filter(pk__lt=10).update(
page__total_earned=F('page__total_earned')+5,
page__profile__balance=F('page__profile__balance')+5
)
Here is a glimpse of my models in case you are wondering:
class Transaction(models.Model):
page = models.ForeignKey(Page, related_name='transactions', null=True, blank=True)
class Page(models.Model):
profile = models.ForeignKey('Profile', related_name='pages', blank=True, null=True)
total_earned = models.IntegerField(default=0)
class Profile(models.Model):
balance = models.IntegerField(default=0, db_index=True)