Mongoengine + Django-tables2: Expected table or queryset, not QuerySet










1















I'm starting to learn django and using it to build and interface to our mongoDB using also mongoengine.
I'm following this tutorial to use django-tables2 but I can't even start it because I get the error Expected table or queryset, not QuerySet.
This is the class I'm using:



class Companies(Document):
url = StringField(required=True, unique=True)
name = StringField(required=True)
founded = IntField()
headquarters = EmbeddedDocumentField(HQ)
description = StringField()


On the view I'm just doing



def companies(request):
return render(request, 'toolbox/companies.html', 'companies': Companies.objects.all())


I see that mongoengine output is a QuerySet type. How can I convert it to some type I can input on django-tables?
Thank you for the help!










share|improve this question




























    1















    I'm starting to learn django and using it to build and interface to our mongoDB using also mongoengine.
    I'm following this tutorial to use django-tables2 but I can't even start it because I get the error Expected table or queryset, not QuerySet.
    This is the class I'm using:



    class Companies(Document):
    url = StringField(required=True, unique=True)
    name = StringField(required=True)
    founded = IntField()
    headquarters = EmbeddedDocumentField(HQ)
    description = StringField()


    On the view I'm just doing



    def companies(request):
    return render(request, 'toolbox/companies.html', 'companies': Companies.objects.all())


    I see that mongoengine output is a QuerySet type. How can I convert it to some type I can input on django-tables?
    Thank you for the help!










    share|improve this question


























      1












      1








      1








      I'm starting to learn django and using it to build and interface to our mongoDB using also mongoengine.
      I'm following this tutorial to use django-tables2 but I can't even start it because I get the error Expected table or queryset, not QuerySet.
      This is the class I'm using:



      class Companies(Document):
      url = StringField(required=True, unique=True)
      name = StringField(required=True)
      founded = IntField()
      headquarters = EmbeddedDocumentField(HQ)
      description = StringField()


      On the view I'm just doing



      def companies(request):
      return render(request, 'toolbox/companies.html', 'companies': Companies.objects.all())


      I see that mongoengine output is a QuerySet type. How can I convert it to some type I can input on django-tables?
      Thank you for the help!










      share|improve this question
















      I'm starting to learn django and using it to build and interface to our mongoDB using also mongoengine.
      I'm following this tutorial to use django-tables2 but I can't even start it because I get the error Expected table or queryset, not QuerySet.
      This is the class I'm using:



      class Companies(Document):
      url = StringField(required=True, unique=True)
      name = StringField(required=True)
      founded = IntField()
      headquarters = EmbeddedDocumentField(HQ)
      description = StringField()


      On the view I'm just doing



      def companies(request):
      return render(request, 'toolbox/companies.html', 'companies': Companies.objects.all())


      I see that mongoengine output is a QuerySet type. How can I convert it to some type I can input on django-tables?
      Thank you for the help!







      python django mongoengine django-tables2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 12:17







      Leo

















      asked Nov 15 '18 at 11:57









      LeoLeo

      112




      112






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The data format django-tables2 expects is a QuerySet, a list of dicts, or something behaving like that. You can create a class inheriting from TableData, pass that to a vanilla django_tables2.Table and put that in your context instead of Companies.objects.all().



          It would look somewhat like this:



          import django_tables2 as tables
          from django_tables2.data import TableQuerysetData


          class TableDocumentData(TableQuerysetData):
          # not sure what to override here, since I do not know the mongoengine API at all


          def companies(request):
          table = CompanyTable(data=TableDocumentData(Companies.objects.all()))

          return render(request, 'toolbox/companies.html', 'companies': table)





          share|improve this answer























          • Thanks for replying! I'm searching for information about TableData and TableQuerysetData in order to find out how to create the TableDocumentData. Just a silly question, what's the CompanyTable on your example? It's the normal "tables.Table" one?

            – Leo
            Nov 22 '18 at 9:31











          • Yes, there are some omissions. I'll try to address this when I have time, if you manage to figure it out in the meantime, consider adding answer to your own question

            – Jieter
            Nov 23 '18 at 9:35










          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',
          autoActivateHeartbeat: false,
          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%2f53318985%2fmongoengine-django-tables2-expected-table-or-queryset-not-queryset%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          The data format django-tables2 expects is a QuerySet, a list of dicts, or something behaving like that. You can create a class inheriting from TableData, pass that to a vanilla django_tables2.Table and put that in your context instead of Companies.objects.all().



          It would look somewhat like this:



          import django_tables2 as tables
          from django_tables2.data import TableQuerysetData


          class TableDocumentData(TableQuerysetData):
          # not sure what to override here, since I do not know the mongoengine API at all


          def companies(request):
          table = CompanyTable(data=TableDocumentData(Companies.objects.all()))

          return render(request, 'toolbox/companies.html', 'companies': table)





          share|improve this answer























          • Thanks for replying! I'm searching for information about TableData and TableQuerysetData in order to find out how to create the TableDocumentData. Just a silly question, what's the CompanyTable on your example? It's the normal "tables.Table" one?

            – Leo
            Nov 22 '18 at 9:31











          • Yes, there are some omissions. I'll try to address this when I have time, if you manage to figure it out in the meantime, consider adding answer to your own question

            – Jieter
            Nov 23 '18 at 9:35















          0














          The data format django-tables2 expects is a QuerySet, a list of dicts, or something behaving like that. You can create a class inheriting from TableData, pass that to a vanilla django_tables2.Table and put that in your context instead of Companies.objects.all().



          It would look somewhat like this:



          import django_tables2 as tables
          from django_tables2.data import TableQuerysetData


          class TableDocumentData(TableQuerysetData):
          # not sure what to override here, since I do not know the mongoengine API at all


          def companies(request):
          table = CompanyTable(data=TableDocumentData(Companies.objects.all()))

          return render(request, 'toolbox/companies.html', 'companies': table)





          share|improve this answer























          • Thanks for replying! I'm searching for information about TableData and TableQuerysetData in order to find out how to create the TableDocumentData. Just a silly question, what's the CompanyTable on your example? It's the normal "tables.Table" one?

            – Leo
            Nov 22 '18 at 9:31











          • Yes, there are some omissions. I'll try to address this when I have time, if you manage to figure it out in the meantime, consider adding answer to your own question

            – Jieter
            Nov 23 '18 at 9:35













          0












          0








          0







          The data format django-tables2 expects is a QuerySet, a list of dicts, or something behaving like that. You can create a class inheriting from TableData, pass that to a vanilla django_tables2.Table and put that in your context instead of Companies.objects.all().



          It would look somewhat like this:



          import django_tables2 as tables
          from django_tables2.data import TableQuerysetData


          class TableDocumentData(TableQuerysetData):
          # not sure what to override here, since I do not know the mongoengine API at all


          def companies(request):
          table = CompanyTable(data=TableDocumentData(Companies.objects.all()))

          return render(request, 'toolbox/companies.html', 'companies': table)





          share|improve this answer













          The data format django-tables2 expects is a QuerySet, a list of dicts, or something behaving like that. You can create a class inheriting from TableData, pass that to a vanilla django_tables2.Table and put that in your context instead of Companies.objects.all().



          It would look somewhat like this:



          import django_tables2 as tables
          from django_tables2.data import TableQuerysetData


          class TableDocumentData(TableQuerysetData):
          # not sure what to override here, since I do not know the mongoengine API at all


          def companies(request):
          table = CompanyTable(data=TableDocumentData(Companies.objects.all()))

          return render(request, 'toolbox/companies.html', 'companies': table)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 19:25









          JieterJieter

          2,98311425




          2,98311425












          • Thanks for replying! I'm searching for information about TableData and TableQuerysetData in order to find out how to create the TableDocumentData. Just a silly question, what's the CompanyTable on your example? It's the normal "tables.Table" one?

            – Leo
            Nov 22 '18 at 9:31











          • Yes, there are some omissions. I'll try to address this when I have time, if you manage to figure it out in the meantime, consider adding answer to your own question

            – Jieter
            Nov 23 '18 at 9:35

















          • Thanks for replying! I'm searching for information about TableData and TableQuerysetData in order to find out how to create the TableDocumentData. Just a silly question, what's the CompanyTable on your example? It's the normal "tables.Table" one?

            – Leo
            Nov 22 '18 at 9:31











          • Yes, there are some omissions. I'll try to address this when I have time, if you manage to figure it out in the meantime, consider adding answer to your own question

            – Jieter
            Nov 23 '18 at 9:35
















          Thanks for replying! I'm searching for information about TableData and TableQuerysetData in order to find out how to create the TableDocumentData. Just a silly question, what's the CompanyTable on your example? It's the normal "tables.Table" one?

          – Leo
          Nov 22 '18 at 9:31





          Thanks for replying! I'm searching for information about TableData and TableQuerysetData in order to find out how to create the TableDocumentData. Just a silly question, what's the CompanyTable on your example? It's the normal "tables.Table" one?

          – Leo
          Nov 22 '18 at 9:31













          Yes, there are some omissions. I'll try to address this when I have time, if you manage to figure it out in the meantime, consider adding answer to your own question

          – Jieter
          Nov 23 '18 at 9:35





          Yes, there are some omissions. I'll try to address this when I have time, if you manage to figure it out in the meantime, consider adding answer to your own question

          – Jieter
          Nov 23 '18 at 9:35



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318985%2fmongoengine-django-tables2-expected-table-or-queryset-not-queryset%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







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3