Hi all,

I am trying to write a Django QuerySet command in my view.py file.

*Simplified Context:*
I have a *Stage* class with a Foreign Key to a *Sample* class. 
(Sample is a blood sample that goes through different stages, such as DNA 
extraction, in LIMS (laboratory information management system)).

I am trying to write a Django query / Python code to retrieve from database 
and send as a parameter to my template, 
*a list (or if possible, iterator) of stage objects *and the *status of the 
most recently modified stage object* as a *tuple.*

I tried this:
sample.stage1_set.latest('date_modified').status
sample.stage1_set.iterator()

where sample is a Sample instance
*status* is an attribute of each Stage instance. However, the only status 
I'm interested in is the
status that corresponds to the latest (last modified) stage. 

But latest() raises DoesNotExist error if sample does not have any stages. 
Without using latest() and thus not
having to write try/ catch, what is a good way to do this? Default values 
for the list of stages and the status are [] and None, respectively.

I'm sending the status of the last modified object because that status 
determines the color of <td> (a column associated with a row)
for all the stage objects. If there is a way to do this on the template 
side, by receiving an iterator object, and updating <td> color
within the for loop that loops over stage objects, that would be amazing.

ex. (in pseudo-code)

<td>
for stage in stages:
   {{ stage }}
    if stage is* last_item_of_stages*:
         * update_color_of_current_td*
</td>


Thank you in advance.
- ML

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to