I am using Django(1.5.4), Python(2.7), sqlite3.
I want to save my user details in sqlite3 database. My code is like this;
This is models.py file.
from django.db import models
class Blog(models.Model):
name = models.CharField(max_length=100)
tagline = models.TextField()
def __unicode__(self):
return self.name
This is my views.py file
def shiva(request):
b = Blog(name='Itons Blog', tagline='All the best to Iton team')
b.save()
print [e.name for e in b.objects.all()]
return HttpResponse("saved")
When i am trying to save the details in sqlite3 the error is coming as;
AttributeError at / Manager isn't accessible via Blog instances
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With