Home > other >  Django beginner, there is a small problem I ask you a great god, annotate and conjunction RawSQL par
Django beginner, there is a small problem I ask you a great god, annotate and conjunction RawSQL par

Time:11-17

Model is trival, write a simple example, beg you great god help me, thank you

/a product entity list
The class Pn (models. Model) :
Pn_id=models. AutoField (primary_key=True)
Pn_name=models. CharField (max_length=50, verbose_name="name")
.

Duration of/product data table
The class PTime (models. Model) :
Pt_id=models. AutoField (primary_key=True)
Pt_pn=models. ForeignKey (Pn, verbose_name="their products")
Pt_sort=models. PositiveIntegerField (verbose_name="process order") according to the process/product production order since the order of production
Pt_time=models. CharField (max_length=50, verbose_name="schedule")
.

Real-time production information/products table
The class PExcute (models. Model) :
Pe_id=models. AutoField (primary_key=True)
Pe_num=models. CharField (max_length=50, verbose_name="number")
Pe_pn=models. ForeignKey (Pn, verbose_name="their products")
Pe_step=models. ForeignKey (PTime, verbose_name="current process")
.

In PExcute admin, I want to a statistical column is the default access to queryset "remaintime", meaning the currently executing task of the rest of the time limit for a project:
Queryset=queryset. Annotate (remaintime=RawSQL (" SELECT SUM (pt_time) FROM PTime table name WHERE pt_sort & gt; AND pt_pn_id==% s % s ", (' pe_step__pt_sort ', 'pe_num__pn_id)))
Here % s is no problem, as if can only use this one, but 'pe_step__pt_sort' and 'pe_num__pn_id' has not access to, the results of a query is None, write whether have problem, how will each record in the queryset some foreign key attribute of the attribute value passed as a parameter to go in
  • Related