django-mongokit
django-mongokit copied to clipboard
How to access function defined in a class?
///////////////////////////////////////////////////////////////////////////////////////////////// @connection.register
class Author(DjangoDocument): collection_name = 'Authors' structure = { 'name': unicode, 'created_at': datetime.datetime }
required_fields = ['name']
default_values = {'created_at':datetime.datetime.utcnow}
use_dot_notation = True
def my_func(self):
print(" my_func working...\n")
/////////////////////////////////////////////////////////////////////////////////////////////////
in shell, i.e. "python manage.py shell"
from
.models import * from django_mongokit import get_database from bson import ObjectId db = get_database()
c_author = db[Author.collection_name]
o_author = c_author.Author()
o_author {'created_at': datetime.datetime(2013, 9, 16, 9, 51, 43, 200898), 'name': None}
o_author.my_func() Traceback (most recent call last): File "
", line 1, in File "/home/tissavadoot/Desktop/Tissproject/TP_MK/local/lib/python2.7/site-packages/mongokit/schema_document.py", line 379, in getattr return dict.getattribute(self, key) AttributeError: 'Author' object has no attribute 'my_func'
I'm stuck over here, need help!!