Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #models.py
- class Orders(models.Model):
- orderid = models.IntegerField(db_column='orderID', primary_key=True)
- pickupdate = models.DateField(db_column='pickupDate', blank=True, null=True)
- pickupstore = models.ForeignKey(Branch, models.DO_NOTHING, db_column='pickupStore', blank=True, null=True,related_name = 'pickupstore')
- class Branch(models.Model):
- branchid = models.IntegerField(db_column='branchID', primary_key=True) # Field name made lowercase.
- city = models.CharField(max_length=45, blank=True, null=True)
- branchs = Orders.objects.all().select_related('returnstore').values('returnstore__city').filter(returndate__year = 2006, returndate__month = 1).annotate(num=Count('returnstore__city')).order_by('returnstore__city')
- branchs = branchs.values('returnstore__city').filter(returndate__year = year, returndate__month = month)
- branchs = branchs.annotate(num=Count('returnstore__city')).order_by('returnstore__city')
Add Comment
Please, Sign In to add comment