i am trying to query base on the id of the table and i get a big error, when i do it using .all() i can get the objects
>>> Restaurant.objects.all()
[<Restaurant: angry dog>, <Restaurant: cafe brazil>, <Restaurant: papa johns>, <Restaurant: lolos>]
[<Restaurant: angry dog>, <Restaurant: cafe brazil>, <Restaurant: papa johns>, <Restaurant: lolos>]
this works for looping and getting the information such
for i in Restaurant.objects.all():
print i.id
print i.name
1
angry dog
2
cafe brazil
3
papa johns
4
lolos
angry dog
2
cafe brazil
3
papa johns
4
lolos
and here when i want to get by the id (or doing name="lolos")
>>> Restaurant.objects.get(id=3)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 345, in get
clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 691, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 709, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1287, in add_q
clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1314, in _add_q
current_negated=current_negated, connector=connector)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1138, in build_filter
lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1076, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1339, in names_to_path
field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\lib\site-packages\django\db\models\options.py", line 416, in get_field_by_name
cache = self.init_name_map()
File "C:\Python27\lib\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 "C:\Python27\lib\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 "C:\Python27\lib\site-packages\django\db\models\options.py", line 577, in _fill_related_many_to_many_cache
for klass in self.apps.get_models():
File "C:\Python27\lib\site-packages\django\utils\lru_cache.py", line 101, in wrapper
result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 168, in get_models
self.check_models_ready()
File "C:\Python27\lib\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.
>>> Restaurant.objects.get(id=3)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 345, in get
clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 691, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 709, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1287, in add_q
clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1314, in _add_q
current_negated=current_negated, connector=connector)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1138, in build_filter
lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1076, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1339, in names_to_path
field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\lib\site-packages\django\db\models\options.py", line 416, in get_field_by_name
cache = self.init_name_map()
File "C:\Python27\lib\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 "C:\Python27\lib\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 "C:\Python27\lib\site-packages\django\db\models\options.py", line 577, in _fill_related_many_to_many_cache
for klass in self.apps.get_models():
File "C:\Python27\lib\site-packages\django\utils\lru_cache.py", line 101, in wrapper
result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 168, in get_models
self.check_models_ready()
File "C:\Python27\lib\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.
reading the tutorials and my book thats it, not sure if i have to activate something somewhere else? or linke bewteen all the files some code?
thanks guys.
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+unsubscribe@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/278ad24d-fe8f-4f92-8021-0e2b8de6d79c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment