class Company models Model name models CharField max_length 200 client

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Company(models.Model)
name = models.CharField(max_length=200)
client_id = models.ForeignKey(User)
class Bill(models.Model)
deal_num = models.CharField(max_length=200)
company = models.ForeignKey(Company)
I do the
>>> Company.objects.filter(client=request.user)
Company 1
---bill 101
---bill 102
---bill 103
Company 2
---bill 5401
---bill 402
---bill 803
Now i wont add search by bill number
And i do the
>>> Company.objects.filter(client=request.user, bill__bill_num__startswith=540)
Result:
Company 2
---bill 5401
---bill 402
---bill 803
But I like it
Company 2
---bill 5401