Commits

Mark Lavin committed ed83a83

Add lookup hooks for adding new items.

Comments (0)

Files changed (1)

selectable/base.py

+import re
 from django.core.urlresolvers import reverse
 from django.core.serializers import json
 from django.http import HttpResponse
     def get_item(self, value):
         return None
 
+    def create_item(self, value):
+        raise NotImplemented()
+
     def format_item(self, item):
          return {
             'id': self.get_item_id(item),
                 pass
         return item
 
+    def create_item(self, value):
+        data = {}
+        if self.search_field:
+            field_name = re.sub(r'__\w+$', '',  self.search_field)
+            if field_name:
+                data = {field_name: value}
+        return self.model(**data)
+