Question: suppose I have the following three models, see as follow: I wanna to construct a Django model query to archive the same effect as the following SQL statement.

**SQL statement**

```
select B.value, C.special
from B inner join C 
where B.version = C.version and B.order = C.order;

```

I got the following three models:

```
class Process(models.Model):
    name = models.CharField(max_length=30)
    description = models.CharField(max_length=150)

class ProcessStep(models.Model):
    process = models.ForeignKey(Process)
    name = models.CharField(max_length=30)
    ...
    order = models.SmallIntegerField(default=1)
    version = models.SmallIntegerField(null=True)

class Approve(models.Model):
    process = models.ForeignKey(Process)
    content = models.CharField(max_length=300)
    ...
    version = models.SmallIntegerField(null=True)
    order = models.SmallIntegerField(default=0)

```

I want to find all Approves that have the same (version, order) tuple matching against the ProcessStep model.

Answer: 
You can combine the usage of [zip()](https://docs.python.org/3/library/functions.html#zip) with [tabulate](https://pypi.python.org/pypi/tabulate) to create a nicer looking table:

```python
from tabulate import tabulate
headers = ['planet', 'amp', 'mass', 'period', 'ecc']    

amp = [1.1, 1.2, 1.3, 1.4]
mass = [2.1, 2.2, 2.3, 2.4]
period = [3.1, 3.2, 3.3, 3.4]
ecc = [4.1, 4.2, 4.3, 4.4]
planet = range(1, len(amp)+1)

table = zip(planet, amp, mass, period, ecc)
print(tabulate(table, headers=headers, floatfmt=".4f"))

```

Output:
-------

```none
  planet     amp    mass    period     ecc
--------  ------  ------  --------  ------
       1  1.1000  2.1000    3.1000  4.1000
       2  1.2000  2.2000    3.2000  4.2000
       3  1.3000  2.3000    3.3000  4.3000
       4  1.4000  2.4000    3.4000  4.4000

```
tabulate.tabulate() takes a list of lists (or arrays) as its main argument, you've given it a list of floats (and a '1').

So you want to put in all your data at once.

You'll need to create new lists where each is one horizontal row of the new table. You'll also need to add the row number at the front.

First build new lists/arrays where:

```
list1=[1,a1,m1,p1,e1]
list2=[2,a2,m2,p2,e2]
...

```

And then try:

```
print tabulate([list1, list2, list3, list4], headers=[...])

```