Wednesday, 15 May 2013

python - Looping through model objects to check whether a field is populated -


I am working on a project project and how to remove the loop through all my "task" model objects Check that many "user" fields are populated by a specific type of user model object.

Is there an easy way to do it all over the model objects?

You do not have to repeat the object. For example, suppose you have a Work is a model like:

  class work (models.Model): user = model.ManyToManyField (user) ...  

The following query will return all tasks objects that contain at least one related user who is a "student":

  Task.ObagesFilter (users__ type = 'student') < / Code> 

d L'underscore ( __ ) Dijengo many-to-say, to overcome many relationships and bring Type user table columns.


No comments:

Post a Comment