orm relation

35 views
Skip to first unread message

bill dexter

unread,
Dec 1, 2019, 9:10:26 AM12/1/19
to Django users
ELECT a.matr
      ,[nom]
      ,[prn]
      ,cast([dat_nais] as date) as dat_nais
  , (YEAR(getdate()) - YEAR(dat_nais)) as age
      ,cast([dat_deces] as date) as dat_deces
      ,cast([dat_imm] as date) as dat_imm
      ,cast([dat_aj] as date) as dat_j
      ,[cod_position]
  ,YEAR(dat_imm) as anne_imm
  ,YEAR(dat_encais) as ann_regl
      ,[annee]
      ,[cod_nat]
      ,cast([dat_e

Snc] as date) as dat_regl
      ,[mt_encais]
  FROM users a
left join enca e on e.matr = a.matr
left join encr c on (c.cod_encais = e.cod_encais)
  where (YEAR(c.dat_enc) - c.annee > 3 ) and ((YEAR(getdate()) - YEAR(a.dat_nais)) between 54 and 70) and c.cod_nat = 'CN'
  order by a.nom_, a.prn, c.annee asc;

hello;
my models are users, enca; encr;
who can i performe this query using django ORM, note that i'm using MSSQL; thank very much

Integr@te System

unread,
Dec 1, 2019, 12:55:43 PM12/1/19
to django...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/85f7f91b-0f52-4a96-8700-bee588eb4a3d%40googlegroups.com.

bill dexter

unread,
Dec 2, 2019, 9:17:00 AM12/2/19
to django...@googlegroups.com
thank you, but if you can give me answer to this  exacte probleme, as mentioned in question 

Integr@te System

unread,
Dec 2, 2019, 2:31:59 PM12/2/19
to django...@googlegroups.com
Hi friend,

All_list = list(users.object.aggregate(age = cast(extractyear(datetime.now()) - extractyear(dat_nais), output_field = IntField())).filter(extractyear(dat_enc) - extractyear(annee)__gt = 3 & extractyear(datetime.now()) - extractyear(dat_nais)__IN=range(54,70) & cod_nad__contain = 'CN').order_by('num___annee', 'prn'))
 

Plz add more alias field as your sql command according to a sample above.

Ps: check your question first(sql), then pass to communities.



bill dexter

unread,
Dec 3, 2019, 7:27:09 AM12/3/19
to django...@googlegroups.com
hi friend;
i tryed your answer, but it says that error in syntax near  __gt  in ""extractyear(dat_enc) - extractyear(annee)__gt = 3""; don't work

Integr@te System

unread,
Dec 3, 2019, 8:18:58 AM12/3/19
to django...@googlegroups.com
Hi issuer,

Plz refer to docs to customize statement base on your use case, my work for a sample with limited time. Plz try remove space around equal sign.



Dvs Khamele

unread,
Dec 12, 2019, 6:08:29 AM12/12/19
to django...@googlegroups.com


Hi We are worlds first affordable Python, Django Based Commpany,
And can help you in this and related tasks / projects immidiately mere at $7 per hour
Best Regards,
Divyesh Khamele,
Pythonmate

--
Reply all
Reply to author
Forward
0 new messages