@spam.global_handler('ForeignKey')
def random_fk(record, field, limit=None):
    Related = field.rel.to
    log.debug('Trying to find related object: %s' % Related)
    models_to_exclude = getattr(settings, 'DILLA_EXCLUDE_MODELS', None)
    if models_to_exclude:
        try:
            excluded_models = [get_model(*m.split('.')) \
                    for m in models_to_exclude]
            if excluded_models in Related:
                log.info('skipping related object [%s] for %s' % \
                        (Related, field.name))
                return None
        except ValueError:
            pass
    try:
        query = Related.objects.all().order_by('?')
        if field.rel.limit_choices_to:
            log.debug('Field %s has limited choices. \
                    Applying to query.' % field)
            query.filter(**field.rel.limit_choices_to)
        if limit:
            return query[:limit]
        return query[0]
    except IndexError, e:
        log.warn('Could not find any related objects for %s' % field.name)
        return None
    except Exception, e:
        log.critical(str(e))
        raise
dataset/ETHPy150Open aerosol/django-dilla/dilla/spammers.py/random_fk/swapped operands of `in`