Reputation: 101
I'm a beginner trying to view a basic queryset with two records. I'm not able to process the request. Looking for some help.
class TestVenue(models.Model):
venue_name = models.CharField(max_length=40)
venue_city = models.CharField(max_length=20, null=True, blank=True)
venue_province = models.CharField(max_length=20, null=True, blank=True)
venue_shortcode = models.CharField(max_length=20, null=True, blank=True)
timestamp = models.DateTimeField(auto_now_add=True)
update = models.DateTimeField(auto_now=True)
my_date_field = models.DateField(auto_now=False, auto_now_add=False)
def __str__(self):
return self.venue_name
my views.py is pretty simple
def venues_listview(request):
template_name = 'venues_list.html'
queryset = TestVenue.objects.all()
context = {
"object_list": queryset
}
return render(request, template_name, context)
from the shell i want to see my queryset but i get the following error:
>>> from venues.models import TestVenue
>>> TestVenue.object.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: type object 'TestVenue' has no attribute 'object'
>>> TestVenue.objects.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\users\frank\desktop\test_env\lib\site-packages\django\db\models\query.py", line 229, in __repr__
return '<%s %r>' % (self.__class__.__name__, data)
File "C:\users\frank\desktop\test_env\lib\site-packages\django\db\models\base.py", line 589, in __repr__
u = six.text_type(self)
File "C:\users\frank\desktop\test_env\src\venues\models.py", line 14, in __str__
# return self.venue_name
TypeError: decoding str is not supported
Upvotes: 1
Views: 304
Reputation: 101
I rebooted my computer and it's now working. I had tried starting and stopping the server but that had not fixed the issue. Thanks for the help.
Upvotes: 0
Reputation: 9235
Your error is in this line,
TestVenue.object.all()
It should be,
TestVenue.objects.all()
objects
is the attribute which calls the default manager, not object
.
Upvotes: 1