[GMG-Devel] [PATCH 18/83] Add method to create a document from a model instance

Alon Levy alon at pobox.com
Tue Feb 25 14:58:01 EST 2014


From: Praveen Kumar <praveen97uma at gmail.com>

---
 mediagoblin/plugins/search/base.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mediagoblin/plugins/search/base.py b/mediagoblin/plugins/search/base.py
index b5f4fa2..c4f12af 100644
--- a/mediagoblin/plugins/search/base.py
+++ b/mediagoblin/plugins/search/base.py
@@ -126,3 +126,16 @@ class SearchIndex(object):
         writer.update_document(**document)
         writer.commit()
 
+    def add_document_from_model_obj(self, model_obj):
+        document = {}
+        for name in self.field_names:
+            try:
+                attr = getattr(model_obj, name)
+                document[name] = attr
+            except AttributeError:
+                _log.info("Attribute %s not found in %s"%(
+                    name, model_obj.__name__))
+        _log.info("Adding document ", document)
+        
+        self.add_document(**document)
+
-- 
1.8.5.3



More information about the devel mailing list