class Beverage(models.Model):
name=models.CharField(max_length=255)
def __unicode__(self):
return self.name
class Location(models.Model):
name=models.CharField(max_length=255)
beverages = models.ManyToManyField(Beverage, through='LocationStandard')
location_number=models.CharField(max_length=255)
organization=models.CharField(max_length=255)
def __unicode__(self):
return self.name
class LocationStandard(models.Model):
beverage=models.ForeignKey(Beverage)
location=models.ForeignKey(Location) #elim this or m2m
start_units=models.IntegerField()
fill_to_standard=models.IntegerField(max_length=10)
order_when_below=models.IntegerField(max_length=10)
class Order(models.Model):
location=models.ForeignKey(Location) #elim this or m2m
beverage=models.ForeignKey(Beverage)
units_ordered=models.IntegerField(max_length=10, default=0)
order_delivered=models.BooleanField(default=False)
timestamp=models.DateTimeField(auto_now_add=True)
user=models.ForeignKey(User)
How can I generate a report that will get me an HTML table with all locations on the x-axis and all beverages on the y-axis. The main thing I am struggling with is just what to query that I can pass the template that I can loop over. Thoughts?
You can’t get them in one query, but you can make something like that (don’t want to setup a whole env to test, so use it as a clue, not a working solution):
The intermediary variables to store querysets are very important, as they allow you to benefit from Django queryset cache.
With Django 1.4 or more, you can replace:
By:
To get a serious perf boost.