How can I filter exported tickets from database using Django?
<p>I am working on a Django based web project where we handle tickets based requests. I am working on an implementation where I need to export all closed tickets everyday.</p>

<p>My ticket table database looks like,</p>

<pre><code>-------------------------------------------------
| ID | ticket_number | ticket_data |  is_closed |
-------------------------------------------------
|  1 |    123123     | data 1      |      1     |
-------------------------------------------------
|  2 |    123124     | data 2      |      1     |
-------------------------------------------------
|  3 |    123125     | data 3      |      1     |
-------------------------------------------------
|  4 |    123126     | data 4      |      1     |
-------------------------------------------------
</code></pre>

<p>And my ticket_exported table in database is similar to </p>

<pre><code>----------------------------------
| ID | ticket_id | ticket_number |
----------------------------------
| 10 |     1     |     123123    |
----------------------------------
| 11 |     2     |     123124    |
----------------------------------
</code></pre>

<p>so my question is that when I process of exporting tickets, is there any way where I can make a single query to  get list of all tickets which are closed but <code>ticket_id</code> and <code>ticket_number</code> is not in <code>ticket_exported</code> table? So when I run functions it should get tickets with <code>ticket_id</code> '3' and '4' because they are not exported in <code>ticket_export</code> database.</p>

<p>I don't want to go through all possible tickets and check one by one if their id exists in exported tickets table if I can just do it in one query whether it is raw SQL query or Django's queries.</p>

<p>Thanks everyone.</p>

<p>you can do without <code>is_exported</code> field: </p>

<pre><code>exported_tickets = TicketsExported.objects.all()
unexported_tickets = Tickets.object.exclude(id__in=[et.id for et in exported_tickets])
</code></pre>

<p>but <code>is_exported</code> field can be useful somewhere else </p>

python mysql django