from chat.models import *
from django.db import connection
c = Campaign.objects.all()[0]
c.reports.all()
[]
import datetime
c.reports.create(type=REPORT_DEFAULT, date=datetime.date.today())
<Report: <Default Report 21>>
c.reports.all()
[<Report: <Default Report 21>>]
c.reports.get_or_create(type=REPORT_DEFAULT, date=datetime.date.today())
(<Report: <Default Report 21>>, False)
a = Agent.objects.all()[0]
c.reports.get_or_create(type=REPORT_AGENT, agent=a, date=datetime.date.today())
(<Report: <Agent Report 22>>, True)
c.reports.all()
[<Report: <Default Report 21>>]
c.reports.get_or_create(type=REPORT_AGENT, agent=a, date=datetime.date.today())
(<Report: <Agent Report 23>>, True)
c.reports.all()
[<Report: <Default Report 21>>]
import pprint
pprint.pprint(connection.queries)
[{'sql': 'SELECT "chat_campaign"."id", "chat_campaign"."user_id", "chat_campaign"."name", "chat_campaign"."chat_title", "chat_campaign"."is_active", "chat_campaign"."date", "chat_campaign"."updated" FROM "chat_campaign" ORDER BY "chat_campaign"."id" ASC LIMIT 1',
'time': '0.003'},
{'sql': 'SELECT "chat_report"."id", "chat_report"."type", "chat_report"."agent_id", "chat_report"."browser", "chat_report"."date", "chat_report"."attempts", "chat_report"."clicks", "chat_report"."interactions", "chat_report"."sales" FROM "chat_report" INNER JOIN "chat_campaign_reports" ON ("chat_report"."id" = "chat_campaign_reports"."report_id") WHERE "chat_campaign_reports"."campaign_id" = 1 ',
'time': '0.002'},
{'sql': 'INSERT INTO "chat_report" ("type", "agent_id", "browser", "date", "attempts", "clicks", "interactions", "sales") VALUES (1, NULL, 0, \'2008-06-20\', 1, 0, 0, 0)',
'time': '0.001'},
{'sql': 'SELECT CURRVAL(\'"chat_report_id_seq"\')', 'time': '0.001'},
{'sql': 'SELECT "report_id" FROM "chat_campaign_reports" WHERE "campaign_id" = 1 AND "report_id" IN (21)',
'time': '0.001'},
{'sql': 'INSERT INTO "chat_campaign_reports" ("campaign_id", "report_id") VALUES (1, 21)',
'time': '0.000'},
{'sql': 'SELECT "chat_report"."id", "chat_report"."type", "chat_report"."agent_id", "chat_report"."browser", "chat_report"."date", "chat_report"."attempts", "chat_report"."clicks", "chat_report"."interactions", "chat_report"."sales" FROM "chat_report" INNER JOIN "chat_campaign_reports" ON ("chat_report"."id" = "chat_campaign_reports"."report_id") WHERE "chat_campaign_reports"."campaign_id" = 1 ',
'time': '0.001'},
{'sql': 'SELECT "chat_report"."id", "chat_report"."type", "chat_report"."agent_id", "chat_report"."browser", "chat_report"."date", "chat_report"."attempts", "chat_report"."clicks", "chat_report"."interactions", "chat_report"."sales" FROM "chat_report" INNER JOIN "chat_campaign_reports" ON ("chat_report"."id" = "chat_campaign_reports"."report_id") WHERE "chat_campaign_reports"."campaign_id" = 1 AND "chat_report"."date" = \'2008-06-20\' AND "chat_report"."type" = 1 ',
'time': '0.001'},
{'sql': 'SELECT "chat_agent"."id", "chat_agent"."user_id", "chat_agent"."campaign_id", "chat_agent"."name", "chat_agent"."photo_id", "chat_agent"."date", "chat_agent"."updated", "chat_agent"."is_active" FROM "chat_agent" ORDER BY "chat_agent"."name" ASC LIMIT 1',
'time': '0.002'},
{'sql': 'SELECT "chat_report"."id", "chat_report"."type", "chat_report"."agent_id", "chat_report"."browser", "chat_report"."date", "chat_report"."attempts", "chat_report"."clicks", "chat_report"."interactions", "chat_report"."sales" FROM "chat_report" INNER JOIN "chat_campaign_reports" ON ("chat_report"."id" = "chat_campaign_reports"."report_id") WHERE "chat_campaign_reports"."campaign_id" = 1 AND "chat_report"."date" = \'2008-06-20\' AND "chat_report"."type" = 2 AND "chat_report"."agent_id" = 2 ',
'time': '0.001'},
{'sql': 'INSERT INTO "chat_report" ("type", "agent_id", "browser", "date", "attempts", "clicks", "interactions", "sales") VALUES (2, 2, 0, \'2008-06-20\', 1, 0, 0, 0)',
'time': '0.001'},
{'sql': 'SELECT CURRVAL(\'"chat_report_id_seq"\')', 'time': '0.000'},
{'sql': 'SELECT "chat_report"."id", "chat_report"."type", "chat_report"."agent_id", "chat_report"."browser", "chat_report"."date", "chat_report"."attempts", "chat_report"."clicks", "chat_report"."interactions", "chat_report"."sales" FROM "chat_report" INNER JOIN "chat_campaign_reports" ON ("chat_report"."id" = "chat_campaign_reports"."report_id") WHERE "chat_campaign_reports"."campaign_id" = 1 ',
'time': '0.001'},
{'sql': 'SELECT "chat_report"."id", "chat_report"."type", "chat_report"."agent_id", "chat_report"."browser", "chat_report"."date", "chat_report"."attempts", "chat_report"."clicks", "chat_report"."interactions", "chat_report"."sales" FROM "chat_report" INNER JOIN "chat_campaign_reports" ON ("chat_report"."id" = "chat_campaign_reports"."report_id") WHERE "chat_campaign_reports"."campaign_id" = 1 AND "chat_report"."date" = \'2008-06-20\' AND "chat_report"."type" = 2 AND "chat_report"."agent_id" = 2 ',
'time': '0.001'},
{'sql': 'INSERT INTO "chat_report" ("type", "agent_id", "browser", "date", "attempts", "clicks", "interactions", "sales") VALUES (2, 2, 0, \'2008-06-20\', 1, 0, 0, 0)',
'time': '0.001'},
{'sql': 'SELECT CURRVAL(\'"chat_report_id_seq"\')', 'time': '0.000'},
{'sql': 'SELECT "chat_report"."id", "chat_report"."type", "chat_report"."agent_id", "chat_report"."browser", "chat_report"."date", "chat_report"."attempts", "chat_report"."clicks", "chat_report"."interactions", "chat_report"."sales" FROM "chat_report" INNER JOIN "chat_campaign_reports" ON ("chat_report"."id" = "chat_campaign_reports"."report_id") WHERE "chat_campaign_reports"."campaign_id" = 1 ',
'time': '0.001'}]
This was fixed in [8415].