Django Union Query -


i need develop union query in django 3 models namely webquery,webreply , businessowners , output should of form below.

{     "(#conversation_id#)_(#b_id#)": {         "from": "(#user_id)",         "email": "(#user_email)",         "date_time": "#get db",         "query": "are open ?",         "from_r_id": "(#representative_id)",         "from_r_name": "(#rep_name)",         "business_registered": "false"         "to_business_name": "ccd saket",         "chat": [{             "direction": 1,             "text": "yes sir",             "date_time": "424 577"         }, {             "direction": 0,             "text": "ok",             "date_time": "424 577"         }]     }, 

i know how query when 1 model involved, not sure of union query. how achieved?

i if going common query recommend making sql view querying that.

w3schools has simple overview of view : http://www.w3schools.com/sql/sql_view.asp

in sql, view virtual table based on result-set of sql statement.

this means can write required sql statement , create view using this. create django model mirrors view can use query.

so, create sql view:

create view view_name     select a, b, c     table_name     condition 

then create django model, has slight difference normal model:

class view_name(models.model):     class meta:         # https://docs.djangoproject.com/en/1.5/ref/models/options/#django.db.models.options.managed         managed = false      = models.charfield(max_length)     .... 

managed = false > https://docs.djangoproject.com/en/1.5/ref/models/options/#django.db.models.options.managed

you can query using normal django orm syntax

or there similar questions:

previous stackoverflow question, union in django orm

how can find union of 2 django querysets?


Comments