Did I find the right examples for you? yes no

All Samples(12)  |  Call(6)  |  Derive(0)  |  Import(6)
Upcast object to it's child.

        def upcast(obj):
    '''Upcast object to it's child.'''

    try:
        return obj._upcast_result
    except AttributeError:
        from django.db.models.query import Collector

        query = obj._default_manager.filter(pk = obj.pk)
        collector = Collector(using = query.db)
        collector.collect(query)

        def cmp_types(left, right):
            if issubclass(left, right):
                return -1
            return 1

        data = sorted(
            map(itemgetter(0), collector.data.values()),
            cmp = cmp_types,
            key = type,
        )

        if data:
            child = data[0]
        else:
            child = obj

        setattr(obj, '_upcast_result', child)
        setattr(child, '_upcast_result', child)
        return child
        


src/d/j/django-dzenlog-0.3.1/django_dzenlog/models.py   django-dzenlog(Download)
 
 
from utils import upcast
 
def published(queryset):

src/d/j/django-dzenlog-0.3.1/django_dzenlog/feeds.py   django-dzenlog(Download)
 
from models import GeneralPost, published
from utils import upcast
from views import get_tagged, get_tags_by_slug
 

src/d/j/django-dzenlog-HEAD/django_dzenlog/models.py   django-dzenlog(Download)
 
 
from utils import upcast
 
def published(queryset):

src/d/j/django-dzenlog-HEAD/django_dzenlog/feeds.py   django-dzenlog(Download)
 
from models import GeneralPost, published
from utils import upcast
from views import get_tagged, get_tags_by_slug
 

src/d/j/django-dzenlog-HEAD/django_dzenlog/tests.py   django-dzenlog(Download)
 
from django.contrib.contenttypes.models import ContentType
from utils import upcast
 
class Upcast(TestCase):
 
        parent_ct = ContentType.objects.get_for_model(parent)
        parent_ct_upcasted = ContentType.objects.get_for_model(upcast(parent))
        child_ct = ContentType.objects.get_for_model(child)
 
        parent1 = Parent.objects.get(id=child1.parent_ptr_id)
        parent1_ct = ContentType.objects.get_for_model(parent1)
        parent1_ct_upcasted = ContentType.objects.get_for_model(upcast(parent1))
 
        parent2 = Parent.objects.get(id=child2.parent_ptr_id)
        parent2_ct = ContentType.objects.get_for_model(parent2)
        parent2_ct_upcasted = ContentType.objects.get_for_model(upcast(parent2))

src/d/j/django-dzenlog-0.3.1/django_dzenlog/tests.py   django-dzenlog(Download)
 
from django.contrib.contenttypes.models import ContentType
from utils import upcast
 
class Upcast(TestCase):
 
        parent_ct = ContentType.objects.get_for_model(parent)
        parent_ct_upcasted = ContentType.objects.get_for_model(upcast(parent))
        child_ct = ContentType.objects.get_for_model(child)
 
        parent1 = Parent.objects.get(id=child1.parent_ptr_id)
        parent1_ct = ContentType.objects.get_for_model(parent1)
        parent1_ct_upcasted = ContentType.objects.get_for_model(upcast(parent1))
 
        parent2 = Parent.objects.get(id=child2.parent_ptr_id)
        parent2_ct = ContentType.objects.get_for_model(parent2)
        parent2_ct_upcasted = ContentType.objects.get_for_model(upcast(parent2))