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










share|improve this question



























    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










    share|improve this question

























      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










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 7:35









      Vineeth Sai

      2,22431023




      2,22431023










      asked Nov 11 at 1:15









      Cloudhaze Cloudhaze

      11




      11



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          27

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          Category:Rhetoric