how to display number of total number of question in my model
up vote
-1
down vote
favorite
i would like to know how i can display the total number of questions in my template using the count()
class Question(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
question_text = models.CharField(max_length=10)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
title = models.CharField(max_length=10)
site_url = models.URLField()
website_type = models.CharField(max_length=100)
budget = models.CharField(max_length=100)
duration = models.CharField(max_length=100)
description = models.TextField()
View.py
@login_required
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
count_project = Question.objects.all().count()
return render(request, 'explore/index.html', 'latest_question_list': latest_question_list, 'count_project': count_project)
index.html
<li><a href="% url 'explore:index' %"id="custom-navbar-list-2">Explore count </a></li>
don't know what am doing wrong please explain using code am kind of new to stackoverflow thanks
django-models
add a comment |
up vote
-1
down vote
favorite
i would like to know how i can display the total number of questions in my template using the count()
class Question(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
question_text = models.CharField(max_length=10)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
title = models.CharField(max_length=10)
site_url = models.URLField()
website_type = models.CharField(max_length=100)
budget = models.CharField(max_length=100)
duration = models.CharField(max_length=100)
description = models.TextField()
View.py
@login_required
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
count_project = Question.objects.all().count()
return render(request, 'explore/index.html', 'latest_question_list': latest_question_list, 'count_project': count_project)
index.html
<li><a href="% url 'explore:index' %"id="custom-navbar-list-2">Explore count </a></li>
don't know what am doing wrong please explain using code am kind of new to stackoverflow thanks
django-models
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
i would like to know how i can display the total number of questions in my template using the count()
class Question(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
question_text = models.CharField(max_length=10)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
title = models.CharField(max_length=10)
site_url = models.URLField()
website_type = models.CharField(max_length=100)
budget = models.CharField(max_length=100)
duration = models.CharField(max_length=100)
description = models.TextField()
View.py
@login_required
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
count_project = Question.objects.all().count()
return render(request, 'explore/index.html', 'latest_question_list': latest_question_list, 'count_project': count_project)
index.html
<li><a href="% url 'explore:index' %"id="custom-navbar-list-2">Explore count </a></li>
don't know what am doing wrong please explain using code am kind of new to stackoverflow thanks
django-models
i would like to know how i can display the total number of questions in my template using the count()
class Question(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
question_text = models.CharField(max_length=10)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
title = models.CharField(max_length=10)
site_url = models.URLField()
website_type = models.CharField(max_length=100)
budget = models.CharField(max_length=100)
duration = models.CharField(max_length=100)
description = models.TextField()
View.py
@login_required
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
count_project = Question.objects.all().count()
return render(request, 'explore/index.html', 'latest_question_list': latest_question_list, 'count_project': count_project)
index.html
<li><a href="% url 'explore:index' %"id="custom-navbar-list-2">Explore count </a></li>
don't know what am doing wrong please explain using code am kind of new to stackoverflow thanks
django-models
django-models
edited Nov 11 at 7:35
Vineeth Sai
2,22431023
2,22431023
asked Nov 11 at 1:15
Cloudhaze Cloudhaze
11
11
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244994%2fhow-to-display-number-of-total-number-of-question-in-my-model%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown