8👍
Your problem is in this line:
print [e.name for e in b.objects.all()] # won't work
b
is a Blog
instance, which will not access the objects Manager. You might try this instead (if you want all rows, which it appears you do since you are creating a list from multiple names):
print [e.name for e in Blog.objects.all()]
Note the use of Blog
instead of b
in Blog.objects.all()
. The objects manager is not accessible via b
but is accessible via the class Blog
.
For further explanation (using an example much like yours), see the docs here.
3👍
b.objects.all()
should be Blog.objects.all()
because the manager (objects) must be accessed from the model class not instances.
- [Django]-ModelForm and error_css_class
- [Django]-Django: Values_list returns id from choice field instead of name
2👍
Well, as the error says, the Manager (.objects
) is only available from the Blog class, not from its instances.
But it’s not clear what you are trying to do. What are you expecting the list comprehension to return?
- [Django]-Django: Formset for adding captions to uploaded images
- [Django]-Using Twisted for asynchronous file uploads from Django app
- [Django]-Why does using .latest() on an empty Django queryset return…nothing?