X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/9b97d5a2faa6f56b439dcefe9c7bb23e0a84b39c..db833ba4517084f61a64907c6d15606e7c881edd:/apps/djangosphinx/management/commands/generate_sphinx_config.py diff --git a/apps/djangosphinx/management/commands/generate_sphinx_config.py b/apps/djangosphinx/management/commands/generate_sphinx_config.py new file mode 100644 index 000000000..3320ce601 --- /dev/null +++ b/apps/djangosphinx/management/commands/generate_sphinx_config.py @@ -0,0 +1,22 @@ +from django.core.management.base import AppCommand +from django.db import models + +from djangosphinx.manager import SphinxModelManager + +class Command(AppCommand): + help = "Prints generic configuration for any models which use a standard SphinxSearch manager." + + output_transaction = True + + def handle_app(self, app, **options): + from djangosphinx.utils.config import generate_config_for_model + model_classes = [getattr(app, n) for n in dir(app) if hasattr(getattr(app, n), '_meta')] + found = 0 + for model in model_classes: + indexes = getattr(model, '__sphinx_indexes__', []) + for index in indexes: + found += 1 + print generate_config_for_model(model, index) + if found == 0: + print "Unable to find any models in application which use standard SphinxSearch configuration." + #return u'\n'.join(sql_create(app, self.style)).encode('utf-8')