I am using django + mongoengine.
Im after the official tutorial, but I have no idea how to enter data in my database.
I don't know if I need to use django console, python console or mongodb
Here is a tutorial example: MongoengineTutorial
Using mongo, I find the following error
(reb_env)root@marcproves:/REBORN/REBORN_PROJ
MongoDB shell version: 2.4.9
connecting to: test
Server has startup warnings:
Tue Apr 1 05:37:35.300 [initandlisten]
Tue Apr 1 05:37:35.300 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!!
Tue Apr 1 05:37:35.301 [initandlisten]
> ross = User(email='ross@example.com', first_name='Ross', last_name='Lawley').save()
Tue Apr 1 06:22:38.046 ReferenceError: User is not defined
> show dbs
local 0.03125GB
reborn 0.203125GB
> use reborn
switched to db reborn
> ross = User(email='ross@example.com', first_name='Ross', last_name='Lawley').save()
Tue Apr 1 06:22:51.791 ReferenceError: User is not defined
I just created an application and added the following code to it:
GNU nano 2.2.6 File: models.py
//from django.db import models
from mongoengine import *
class User(Document):
email = StringField(required=True)
first_name = StringField(max_length=50)
last_name = StringField(max_length=50)
class Post(Document):
title = StringField(max_length=120, required=True)
author = ReferenceField(User, reverse_delete_rule=CASCADE)
tags = ListField(StringField(max_length=30))
comments = ListField(EmbeddedDocumentField(Comment))
meta = {'allow_inheritance': True}
class TextPost(Post):
content = StringField()
class ImagePost(Post):
image_path = StringField()
class LinkPost(Post):
link_url = StringField()
class Comment(EmbeddedDocument):
content = StringField()
name = StringField(max_length=120)
UPDATED: Done in django shell
(reb_env)root@marcproves:/REBORN/REBORN_PROJ
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from mongoengine import *
>>> connect('reborn')
MongoClient('localhost', 27017)
>>> ross = User(email='ross@example.com', first_name='Ross', last_name='Lawley').save()
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'User' is not defined
>>>
And the same error, the user is not defined, what should I do?