~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to pybb/orm.py

  • Committer: Holger Rapp
  • Date: 2016-08-08 10:06:42 UTC
  • mto: This revision was merged to the branch mainline in revision 419.
  • Revision ID: sirver@gmx.de-20160808100642-z62vwqitxoyl5fh4
Added the apt-get update script I run every 30 days.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
def load_related(objects, rel_qs, rel_field_name, cache_field_name=None):
2
 
    """Load in one SQL query the objects from query set (rel_qs) which is
3
 
    linked to objects from (objects) via the field (rel_field_name)."""
 
2
    """
 
3
    Load in one SQL query the objects from query set (rel_qs)
 
4
    which is linked to objects from (objects) via the field (rel_field_name).
 
5
    """
4
6
 
5
7
    obj_map = dict((x.id, x) for x in objects)
6
8
    rel_field = rel_qs.model._meta.get_field(rel_field_name)
10
12
 
11
13
    temp_map = {}
12
14
    for rel_obj in rel_objects:
13
 
        pk = getattr(rel_obj, rel_field.attname)
 
15
        pk = getattr(rel_obj, rel_field.attname )
14
16
        temp_map.setdefault(pk, []).append(rel_obj)
15
17
 
16
18
    for pk, rel_list in temp_map.iteritems():