Changes between Initial Version and Version 1 of Ticket #7516


Ignore:
Timestamp:
Jun 23, 2008, 12:42:35 PM (16 years ago)
Author:
Ramiro Morales
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #7516 – Description

    initial v1  
    33Seems like m2m.get_or_create is not actually creating entries in the actual "mapping table" in the database... See below.
    44
    5 from chat.models import *[[BR]]
    6 from django.db import connection[[BR]]
    7 c = Campaign.objects.all()[0][[BR]]
    8 c.reports.all()[[BR]]
    9 [][[BR]]
    10 import datetime[[BR]]
    11 c.reports.create(type=REPORT_DEFAULT, date=datetime.date.today())[[BR]]
    12 <Report: <Default Report 21>>[[BR]]
    13 c.reports.all()[[BR]]
    14 [<Report: <Default Report 21>>][[BR]]
    15 c.reports.get_or_create(type=REPORT_DEFAULT, date=datetime.date.today())[[BR]]
    16 (<Report: <Default Report 21>>, False)[[BR]]
    17 a = Agent.objects.all()[0][[BR]]
    18 c.reports.get_or_create(type=REPORT_AGENT, agent=a, date=datetime.date.today())[[BR]]
    19 (<Report: <Agent Report 22>>, True)[[BR]]
    20 c.reports.all()[[BR]]
    21 [<Report: <Default Report 21>>][[BR]]
    22 c.reports.get_or_create(type=REPORT_AGENT, agent=a, date=datetime.date.today())[[BR]]
    23 (<Report: <Agent Report 23>>, True)[[BR]]
    24 c.reports.all()[[BR]]
    25 [<Report: <Default Report 21>>][[BR]]
    26  
    27 import pprint[[BR]]
    28 pprint.pprint(connection.queries)[[BR]]
     5{{{
     6#!python
     7from chat.models import *
     8from django.db import connection
     9c = Campaign.objects.all()[0]
     10c.reports.all()
     11[]
     12import datetime
     13c.reports.create(type=REPORT_DEFAULT, date=datetime.date.today())
     14<Report: <Default Report 21>>
     15c.reports.all()
     16[<Report: <Default Report 21>>]
     17c.reports.get_or_create(type=REPORT_DEFAULT, date=datetime.date.today())
     18(<Report: <Default Report 21>>, False)
     19a = Agent.objects.all()[0]
     20c.reports.get_or_create(type=REPORT_AGENT, agent=a, date=datetime.date.today())
     21(<Report: <Agent Report 22>>, True)
     22c.reports.all()
     23[<Report: <Default Report 21>>]
     24c.reports.get_or_create(type=REPORT_AGENT, agent=a, date=datetime.date.today())
     25(<Report: <Agent Report 23>>, True)
     26c.reports.all()
     27[<Report: <Default Report 21>>]
     28
     29import pprint
     30pprint.pprint(connection.queries)
    2931[{'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',
    3032  'time': '0.003'},
     
    5860 {'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 ',
    5961  'time': '0.001'}]
    60 
     62}}}
    6163
    6264I can verify via "select * from chat_campaign_reports;" that the mapping is not being inserted.
Back to Top