<commit_before>import things
from django.db import connection

class TribeThing(things.ModelThing):
    created = things.OrderField(verbose_name_asc='Oldest', 
        verbose_name_desc='Newest', url_asc='oldest', url_desc='newest', 
        field_url='date')
    name = things.OrderField()
    member_count = things.OrderField(verbose_name_asc='Smallest', 
        verbose_name_desc='Largest', url_asc='smallest', url_desc='largest',
        field_url='size')
    search = ('name', 'description')
    template_dir = 'tribes'
    list_template_name = 'tribes.html'
    
    def get_query_set(self, m2m_name='members'):
        m2m_field = self.model._meta.get_field(m2m_name)
        qn = connection.ops.quote_name
        SQL = """
        SELECT COUNT(*) 
        FROM %(m2m_table)s 
        WHERE %(m2m_table)s.%(column_name)s = %(self_table)s.id
        """ % {
            'm2m_table': qn(m2m_field.m2m_db_table()),
            'column_name': qn(m2m_field.m2m_column_name()),
            'self_table': qn(self.model._meta.db_table),
        }
        print SQL
        return self.model._default_manager.extra(select={'member_count': SQL})<commit_msg>Fixed support for ordering tribes and projects by number of members.<commit_after>import things
from django.db import connection

class TribeThing(things.ModelThing):
    created = things.OrderField(verbose_name_asc='Oldest', 
        verbose_name_desc='Newest', url_asc='oldest', url_desc='newest', 
        field_url='date')
    name = things.OrderField()
    member_count = things.OrderField(verbose_name_asc='Smallest', 
        verbose_name_desc='Largest', url_asc='smallest', url_desc='largest',
        field_url='size')
    search = ('name', 'description')
    template_dir = 'tribes'
    list_template_name = 'tribes.html'
    
    def get_query_set(self, m2m_name='members'):
        m2m_field = self.model._meta.get_field(m2m_name)
        qn = connection.ops.quote_name
        SQL = """
        SELECT COUNT(*) 
        FROM %(m2m_table)s 
        WHERE %(m2m_table)s.%(column_name)s = %(self_table)s.id
        """ % {
            'm2m_table': qn(m2m_field.m2m_db_table()),
            'column_name': qn(m2m_field.m2m_column_name()),
            'self_table': qn(self.model._meta.db_table),
        }
        return self.model._default_manager.extra(select={'member_count': SQL})
{'fraction_non_alphanumeric': 0.13239676458067262, 'fraction_numerical': 0.008514261387824606, 'mean_word_length': 3.226618705035971, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2457508', 'n_tokens_mistral': 815, 'n_tokens_neox': 786, 'n_words': 117}