notorhot/models.py
def generate_from_queryset(self, queryset):
        """
        Selects two :class:`Candidate` instances at random from the specified
        queryset, and creates a new :class:`Competition` between them.
        
        :arg queryset: pool of :class:`Candidate` instances from which to select
        :type queryset: :class:`QuerySet`
        :raises: :exc:`CompetitionGeneratingManager.NonMatchingCategory` if
            ``queryset`` contains candidates from multiple categories
        :returns: new :class:`Competition` between two :class:`Candidate` 
            instances selected at random from ``queryset``
        :rtype: :class:`Competition`         
        """
        # Make sure our queryset only contains Candidates from a single Category
        # Because .values(), .order_by(), and .distinct() can interfere with one
        # another, and we can't guarantee that no ordering is applied, we can't
        # do this in the ORM and thus must instead handle it in Python.  Yuck.
        category_ids = queryset.values_list('category__id', flat=True)
        category_ids = set(category_ids)
        if len(category_ids) > 1:
            raise self.NonMatchingCategory()            

        # randomize queryset order, then select first two objects
        first_2 = queryset.order_by('?')[:2]
        
        # Not enough candidates available total
        if len(first_2) < 2:
            raise Candidate.DoesNotExist

        return self.generate_from_candidates(first_2[0], first_2[1])

        Selects two :class:`Candidate` instances at random from the specified
        queryset, and creates a new :class:`Competition` between them.
        
        :arg queryset: pool of :class:`Candidate` instances from which to select
        :type queryset: :class:`QuerySet`
        :raises: :exc:`CompetitionGeneratingManager.NonMatchingCategory` if
            ``queryset`` contains candidates from multiple categories
        :returns: new :class:`Competition` between two :class:`Candidate` 
            instances selected at random from ``queryset``
        :rtype: :class:`Competition`         
        
Selects two :class:`Candidate` instances at random from the specified
queryset, and creates a new :class:`Competition` between them.
Selects two : class : ` Candidate ` instances at random from the specified queryset and creates a new : class : ` Competition ` between them .
def generate_from_queryset(self, queryset):
        category_ids = queryset.values_list('category__id', flat=True)
        category_ids = set(category_ids)
        if len(category_ids) > 1:
            raise self.NonMatchingCategory()            
        first_2 = queryset.order_by('?')[:2]
        if len(first_2) < 2:
            raise Candidate.DoesNotExist
        return self.generate_from_candidates(first_2[0], first_2[1])
def generate_from_queryset ( self , queryset ) : category_ids = queryset . values_list ( 'category__id' , flat = True ) category_ids = set ( category_ids ) if len ( category_ids ) > 1 : raise self . NonMatchingCategory ( ) first_2 = queryset . order_by ( '?' ) [ : 2 ] if len ( first_2 ) < 2 : raise Candidate . DoesNotExist return self . generate_from_candidates ( first_2 [ 0 ] , first_2 [ 1 ] )
Selects two :class:`Candidate` instances at random from the specified
queryset, and creates a new :class:`Competition` between them.
Selects two : class : ` Candidate ` instances at random from the specified queryset and creates a new : class : ` Competition ` between them .
"""
        Selects two :class:`Candidate` instances at random from the specified
        queryset, and creates a new :class:`Competition` between them.
        
        :arg queryset: pool of :class:`Candidate` instances from which to select
        :type queryset: :class:`QuerySet`
        :raises: :exc:`CompetitionGeneratingManager.NonMatchingCategory` if
            ``queryset`` contains candidates from multiple categories
        :returns: new :class:`Competition` between two :class:`Candidate` 
            instances selected at random from ``queryset``
        :rtype: :class:`Competition`         
        """ # Make sure our queryset only contains Candidates from a single Category # Because .values(), .order_by(), and .distinct() can interfere with one # another, and we can't guarantee that no ordering is applied, we can't # do this in the ORM and thus must instead handle it in Python.  Yuck. # randomize queryset order, then select first two objects # Not enough candidates available total
new :class:`Competition` between two :class:`Candidate`
instances selected at random from ``queryset``
new : class : ` Competition ` between two : class : ` Candidate ` instances selected at random from ` ` queryset ` `
:class:`Competition`
:exc:`CompetitionGeneratingManager.NonMatchingCategory` if
``queryset`` contains candidates from multiple categories
: exc : ` CompetitionGeneratingManager . NonMatchingCategory ` if ` ` queryset ` ` contains candidates from multiple categories
self
queryset
pool of :class:`Candidate` instances from which to select
pool of : class : ` Candidate ` instances from which to select