2

I have created a fake course in django-cms Studio to test my app and now I need to retrieve some data from Mongodb. Here is my code:

models.py:

from django.db import models
from django.contrib.auth.models import User

class Recomendacion(models.Model):

    id_usuario = models.ForeignKey(User, db_column='user_id', primary_key=True)
    id_recurso = models.CharField(max_length=255, db_column='next_module')

    def __str__(self):
        return self.id_usuario

    def __str__(self):
        return self.id_recurso

    def obtener_id(self):
        return self.id_usuario.pk

    def obtener_full_name(self):
        return self.id_usuario.get_full_name()

admin.py:

from django.contrib import admin
from recomendador.models import Recomendacion

class RecomendacionAdmin(admin.ModelAdmin):    

    fields = ['id_usuario', 'id_recurso']
    list_display = ['obtener_id', 'id_usuario','obtener_full_name', 'id_recurso']

admin.site.register(Recomendacion, RecomendacionAdmin)

And now I would like to add a classmethod in Recomendacion to retrieve the data, something like that:

db.modulestore.find({"_id.org":"uc3m", "_id.category": "problem"})

I don't know if that is correct, because I am new to all this. And I think I have to Import some packages because I get all the time:

NameError: name 'db' is not defined

How can I do it?

Bertrand Marron
  • 21,501
  • 8
  • 58
  • 94
  • Similar issues, http://stackoverflow.com/questions/11959719/web2py-db-is-not-defined http://stackoverflow.com/questions/27632513/why-do-i-get-a-nameerror-with-this-import – Isanka Wijerathne Feb 18 '15 at 07:22

0 Answers0