Finding related objects for instances in a queryset

1
2
3
4
5
6
7
8
9
from django.db.models.deletion import Collector
from django.db import router
from myapp.models import MyModel

def get_related(queryset):
    using = router.db_for_read(queryset.model)
    coll = Collector(using=using)
    coll.collect(queryset)
    return coll.data

More like this

  1. Bitwise operator queryset filter by hgeerts@osso.nl 3 years ago
  2. ParentModel and ChildManager for Model Inheritance by jpwatts 4 years, 8 months ago
  3. Modifying the fields of a third/existing model class by marinho 2 years, 4 months ago
  4. Signal to post new saved objects to Twitter by arthurfurlan 4 years, 2 months ago
  5. A ModelChoiceField with support for title in options based on a field in the model by celopes 2 years, 9 months ago

Comments

(Forgotten your password?)