Skip to content

NameError: name 'basestring' is not defined #57

Open
@ignacionf

Description

@ignacionf

i has this error in a clean code:

14:25 $ git diff
diff --git a/requeriments.txt b/requeriments.txt
index 47d501b..5f36098 100644
--- a/requeriments.txt
+++ b/requeriments.txt
@@ -29,3 +29,5 @@ django-ajax-selects==1.4.1
 Babel==2.3.4
 django-compressor==2.1
 django-libsass==0.7
+elasticsearch==2.3.0
+git+https://github.com/liberation/django_elasticsearch.git
diff --git a/uniresto/products/models.py b/uniresto/products/models.py
index c78781d..4928754 100644
--- a/uniresto/products/models.py
+++ b/uniresto/products/models.py
@@ -9,6 +9,8 @@ from imagekit.processors import ResizeToFill
 from image_cropping import ImageRatioField
 from enum import Enum
 from django.utils.text import slugify
+from django_elasticsearch.models import EsIndexable
+


 COMBO_PRODUCT_TYPES = (
@@ -166,7 +168,7 @@ class Category(models.Model):
         verbose_name_plural = 'Categorias de productos (Pasta, carnes, etc).'


-class ProductTemplates(models.Model):
+class ProductTemplates(EsIndexable, models.Model):
     """
     Almacena plantillas de productos por categorias. Se utiliza para agilizar el registro de todos los productos
     de marca comercial o no ya definidos.
14:36 $ 

in settings:

ELASTICSEARCH_URL='http://localhost:9200'
ELASTICSEARCH_AUTO_INDEX=True
ELASTICSEARCH_DEFAULT_INDEX='uniresto'

Tracktrace:

NameError                                 Traceback (most recent call last)
<ipython-input-3-be67e0bf0776> in <module>()
----> 1 ProductTemplates(name="caca", category=o, celiac=False, delivery=True, consumed_in_store=True, max_choices=1).save()

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/models.py in save(self, *args, **kwargs)
     52     def save(self, *args, **kwargs):
     53         self._raise_no_db_operation()
---> 54         super(EsIndexable, self).save(*args, **kwargs)
     55 
     56     def delete(self, *args, **kwargs):

/home/ignacio/uniresto/lib/python3.5/site-packages/django/db/models/base.py in save(self, force_insert, force_update, using, update_fields)
    708 
    709         self.save_base(using=using, force_insert=force_insert,
--> 710                        force_update=force_update, update_fields=update_fields)
    711     save.alters_data = True
    712 

/home/ignacio/uniresto/lib/python3.5/site-packages/django/db/models/base.py in save_base(self, raw, force_insert, force_update, using, update_fields)
    745         if not meta.auto_created:
    746             signals.post_save.send(sender=origin, instance=self, created=(not updated),
--> 747                                    update_fields=update_fields, raw=raw, using=using)
    748 
    749     save_base.alters_data = True

/home/ignacio/uniresto/lib/python3.5/site-packages/django/dispatch/dispatcher.py in send(self, sender, **named)
    199 
    200         for receiver in self._live_receivers(sender):
--> 201             response = receiver(signal=self, sender=sender, **named)
    202             responses.append((receiver, response))
    203         return responses

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/models.py in es_save_callback(sender, instance, **kwargs)
     70     if not issubclass(sender, EsIndexable):
     71         return
---> 72     instance.es.do_index()
     73 
     74 

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/managers.py in wrapper(*args, **kwargs)
     44         if args[0].instance is None:
     45             raise AttributeError("This method requires an instance of the model.")
---> 46         return f(*args, **kwargs)
     47     return wrapper
     48 

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/managers.py in do_index(self)
    122     @needs_instance
    123     def do_index(self):
--> 124         body = self.serialize()
    125         es_client.index(index=self.index,
    126                         doc_type=self.doc_type,

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/managers.py in wrapper(*args, **kwargs)
     44         if args[0].instance is None:
     45             raise AttributeError("This method requires an instance of the model.")
---> 46         return f(*args, **kwargs)
     47     return wrapper
     48 

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/managers.py in serialize(self)
    101         Note: by default, will use all the model's fields.
    102         """
--> 103         serializer = self.get_serializer()
    104         return serializer.serialize(self.instance)
    105 

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/managers.py in get_serializer(self, **kwargs)
     88     def get_serializer(self, **kwargs):
     89         serializer = self.model.Elasticsearch.serializer_class
---> 90         if isinstance(serializer, basestring):
     91             module, kls = self.model.Elasticsearch.serializer_class.rsplit(".", 1)
     92             mod = importlib.import_module(module)

NameError: name 'basestring' is not defined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions