Hello, please help!

Some of my models throw this error, when I query them with object.all(). 
They coexist in apps that have other models that are just fine. I do not 
understand at all what the problem might be and could not google it. 

For example: this would be my models.py in the app "account":

from django.db import models
from django.contrib.auth.models import User
from apps.courseevent.models import CourseParticipation
from apps.transaction.models import Transaction
from model_utils.fields import SplitField
from model_utils.models import TimeStampedModel
from money import Money

class UserStatus(TimeStampedModel):
    status_code = models.CharField(max_length=20)
    title = models.CharField(max_length=100)
    text = models.TextField()

    def __unicode__(self):
        return u"%s" % (self.title)

class UserAccount(TimeStampedModel):
    user = models.ForeignKey(User, unique=True)
    about = SplitField()
    status = models.ForeignKey(UserStatus)

    def __unicode__(self):
        return u"%s %s" % (self.user.first_name, self.user.last_name)

    def balance(self):
        balance = Money(amount='0.00', currency='EUR')
        transactions = Transaction.objects.filter(user=self.user_id)
        for transaction in transactions:
            try:
               transaction_value = Money(amount=transaction.total , 
currency='EUR' )
               balance = balance + transaction_value
            except:
               pass
        return balance

    def participation_level(self):
        try:
            CourseParticipation.objects.filter(participant=self.user_id,
                role = CourseParticipation.ROLE_TEACHER)
            return CourseParticipation.ROLE_TEACHER
        except:
            try:
                CourseParticipation.objects.filter(participant=self.user_id,
                    role = CourseParticipation.ROLE_STUDENT)
                return CourseParticipation.ROLE_STUDENT
            except:
                return None


Then I try to call them via the Python.shell:
>>>>from apps.account.models import UserStatus, UserAccount 
>>>>x =  UserStatus.objects.all()
>>>>y = UserAccount.objects.all()
>>>>print x
[<UserStatus: Angemeldet>, <UserStatus: Lehrer-Anwaerter>]
>>>>print y
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/query.py",
 
line 119, in __repr__
    return repr(data)
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/base.py",
 
line 459, in __repr__
    u = six.text_type(self)
  File 
"/Users/sabinemaennel/PycharmProjects/netteachers/apps/account/models.py", 
line 23, in __unicode__
    return u"%s %s" % (self.user.first_name, self.user.last_name)
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/fields/related.py",
 
line 557, in __get__
    val = self.field.get_local_related_value(instance)
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/fields/related.py",
 
line 1429, in get_local_related_value
    return self.get_instance_value_for_fields(instance, 
self.local_related_fields)
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/fields/related.py",
 
line 1422, in local_related_fields
    return tuple(lhs_field for lhs_field, rhs_field in self.related_fields)
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/fields/related.py",
 
line 1413, in related_fields
    self._related_fields = self.resolve_related_fields()
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/fields/related.py",
 
line 1406, in resolve_related_fields
    else self.rel.to._meta.get_field_by_name(to_field_name)[0])
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/options.py",
 
line 416, in get_field_by_name
    cache = self.init_name_map()
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/options.py",
 
line 445, in init_name_map
    for f, model in self.get_all_related_m2m_objects_with_model():
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/options.py",
 
line 563, in get_all_related_m2m_objects_with_model
    cache = self._fill_related_many_to_many_cache()
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/db/models/options.py",
 
line 577, in _fill_related_many_to_many_cache
    for klass in self.apps.get_models():
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/utils/lru_cache.py",
 
line 101, in wrapper
    result = user_function(*args, **kwds)
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/apps/registry.py",
 
line 168, in get_models
    self.check_models_ready()
  File 
"/Users/sabinemaennel/VirtualEnvs/netteachers/lib/python2.7/site-packages/django/apps/registry.py",
 
line 131, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
AppRegistryNotReady: Models aren't loaded yet.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/66674b88-400f-4718-951a-063bc13428ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to