import datetime
from django.db import models
from django.utils import timezone
class Question(models.Model):
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
def __str__(self):
return self.question_text
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
def __str__(self):
return self.choice_text
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
obj = Question.objects.all()
obj2 = models.Model.objects.all()
Asked
Active
Viewed 31 times
0

markwalker_
- 12,078
- 7
- 62
- 99
-
What does "not recognised by python" mean? `obj` should include all of your `Question` objects, `obj2` won't work. – markwalker_ Feb 03 '20 at 23:56
-
the class Question inherit (models.Model) so both them should have objects.all() and other method such filter, get, etc. but both of them doesn't show those suggestions – herald_the_sentinel Feb 04 '20 at 00:11
-
That's not true. A default manager is added when your `Question` class is prepared. If you just try to access the manager of `models.Model` you'll get `AttributeError: type object 'Model' has no attribute 'objects'` – markwalker_ Feb 04 '20 at 00:34