TypeError: 'ModelBase' object does not support indexing.












1















I created the models.py file and when I try to execute the 'makemigrations' command, I get the following error:



    return bool(self.related_name) and self.related_name[-1] == '+'
TypeError: 'ModelBase' object does not support indexing


I tried to find a forum reply, but the topics mainly concern the error that appears from the views.py file. In my situations, this file has not been created yet.



Any help will be appreciated, also about the more transparent code in the database.



My models.py



from django.db import models


#additives
class TestUser(models.Model):
name = models.CharField(max_length=50)

class Trade(models.Model):
all_trade_here = models.TextField()

class ImageGallery(models.Model):
image = models.ImageField()

class SocialMediaLinks(models.Model):
link = models.URLField()

# Option for premium user
class Prem_PhotoGallery(models.Model):
name_photo_gallery = models.CharField(max_length=50)
image_gallery = models.ForeignKey(ImageGallery,
on_delete=models.CASCADE)

class Prem_PDF(models.Model):
name_pdf = models.CharField(max_length=50)
file = models.FileField()

class Prem_YouTube(models.Model):
name_youtube = models.CharField(max_length=50)
link = models.URLField()

class Prem_VilmVeo(models.Model):
name_vilmveo = models.CharField(max_length=50)
link = models.URLField()

class Prem_Audio(models.Model):
name_audio = models.CharField(max_length=50)
link = models.URLField()

class Prem_Website(models.Model):
name_website = models.CharField(max_length=50)
link = models.URLField()

class Prem_SocialMedia(models.Model):
name_social_button_1 = models.CharField(max_length=50)
links = models.ForeignKey(SocialMediaLinks, on_delete=models.CASCADE)

class Prem_GoogleMaps(models.Model):
name_google_maps = models.CharField(max_length=50)
link = models.URLField()

# element write by user
class Person(models.Model):
#basic information, all write user
name = models.CharField(max_length=100)
surname = models.CharField(max_length=100)
phone = models.CharField(max_length=15)
e_mail = models.EmailField(max_length=100)
website = models.URLField(max_length=250)
photo = models.FileField()
small_photo = models.FileField()
description = models.TextField()
recommended_by = models.ForeignKey(TestUser,
on_delete=models.CASCADE)
my_projects = models.ManyToManyField(Prem_PhotoGallery,
Prem_PDF,
Prem_YouTube,
Prem_VilmVeo,
Prem_Audio,
Prem_Website,
Prem_SocialMedia,
Prem_GoogleMaps,
blank=True)
keywords = models.TextField()
trade = models.ManyToManyField(Trade)

#premium
premium_accounts = models.BooleanField(default=False)

#location
city = models.CharField(max_length=100)
street = models.CharField(max_length=100)
zip_code = models.CharField(max_length=8)

#data joined
time_create_account = models.DateTimeField()









share|improve this question



























    1















    I created the models.py file and when I try to execute the 'makemigrations' command, I get the following error:



        return bool(self.related_name) and self.related_name[-1] == '+'
    TypeError: 'ModelBase' object does not support indexing


    I tried to find a forum reply, but the topics mainly concern the error that appears from the views.py file. In my situations, this file has not been created yet.



    Any help will be appreciated, also about the more transparent code in the database.



    My models.py



    from django.db import models


    #additives
    class TestUser(models.Model):
    name = models.CharField(max_length=50)

    class Trade(models.Model):
    all_trade_here = models.TextField()

    class ImageGallery(models.Model):
    image = models.ImageField()

    class SocialMediaLinks(models.Model):
    link = models.URLField()

    # Option for premium user
    class Prem_PhotoGallery(models.Model):
    name_photo_gallery = models.CharField(max_length=50)
    image_gallery = models.ForeignKey(ImageGallery,
    on_delete=models.CASCADE)

    class Prem_PDF(models.Model):
    name_pdf = models.CharField(max_length=50)
    file = models.FileField()

    class Prem_YouTube(models.Model):
    name_youtube = models.CharField(max_length=50)
    link = models.URLField()

    class Prem_VilmVeo(models.Model):
    name_vilmveo = models.CharField(max_length=50)
    link = models.URLField()

    class Prem_Audio(models.Model):
    name_audio = models.CharField(max_length=50)
    link = models.URLField()

    class Prem_Website(models.Model):
    name_website = models.CharField(max_length=50)
    link = models.URLField()

    class Prem_SocialMedia(models.Model):
    name_social_button_1 = models.CharField(max_length=50)
    links = models.ForeignKey(SocialMediaLinks, on_delete=models.CASCADE)

    class Prem_GoogleMaps(models.Model):
    name_google_maps = models.CharField(max_length=50)
    link = models.URLField()

    # element write by user
    class Person(models.Model):
    #basic information, all write user
    name = models.CharField(max_length=100)
    surname = models.CharField(max_length=100)
    phone = models.CharField(max_length=15)
    e_mail = models.EmailField(max_length=100)
    website = models.URLField(max_length=250)
    photo = models.FileField()
    small_photo = models.FileField()
    description = models.TextField()
    recommended_by = models.ForeignKey(TestUser,
    on_delete=models.CASCADE)
    my_projects = models.ManyToManyField(Prem_PhotoGallery,
    Prem_PDF,
    Prem_YouTube,
    Prem_VilmVeo,
    Prem_Audio,
    Prem_Website,
    Prem_SocialMedia,
    Prem_GoogleMaps,
    blank=True)
    keywords = models.TextField()
    trade = models.ManyToManyField(Trade)

    #premium
    premium_accounts = models.BooleanField(default=False)

    #location
    city = models.CharField(max_length=100)
    street = models.CharField(max_length=100)
    zip_code = models.CharField(max_length=8)

    #data joined
    time_create_account = models.DateTimeField()









    share|improve this question

























      1












      1








      1








      I created the models.py file and when I try to execute the 'makemigrations' command, I get the following error:



          return bool(self.related_name) and self.related_name[-1] == '+'
      TypeError: 'ModelBase' object does not support indexing


      I tried to find a forum reply, but the topics mainly concern the error that appears from the views.py file. In my situations, this file has not been created yet.



      Any help will be appreciated, also about the more transparent code in the database.



      My models.py



      from django.db import models


      #additives
      class TestUser(models.Model):
      name = models.CharField(max_length=50)

      class Trade(models.Model):
      all_trade_here = models.TextField()

      class ImageGallery(models.Model):
      image = models.ImageField()

      class SocialMediaLinks(models.Model):
      link = models.URLField()

      # Option for premium user
      class Prem_PhotoGallery(models.Model):
      name_photo_gallery = models.CharField(max_length=50)
      image_gallery = models.ForeignKey(ImageGallery,
      on_delete=models.CASCADE)

      class Prem_PDF(models.Model):
      name_pdf = models.CharField(max_length=50)
      file = models.FileField()

      class Prem_YouTube(models.Model):
      name_youtube = models.CharField(max_length=50)
      link = models.URLField()

      class Prem_VilmVeo(models.Model):
      name_vilmveo = models.CharField(max_length=50)
      link = models.URLField()

      class Prem_Audio(models.Model):
      name_audio = models.CharField(max_length=50)
      link = models.URLField()

      class Prem_Website(models.Model):
      name_website = models.CharField(max_length=50)
      link = models.URLField()

      class Prem_SocialMedia(models.Model):
      name_social_button_1 = models.CharField(max_length=50)
      links = models.ForeignKey(SocialMediaLinks, on_delete=models.CASCADE)

      class Prem_GoogleMaps(models.Model):
      name_google_maps = models.CharField(max_length=50)
      link = models.URLField()

      # element write by user
      class Person(models.Model):
      #basic information, all write user
      name = models.CharField(max_length=100)
      surname = models.CharField(max_length=100)
      phone = models.CharField(max_length=15)
      e_mail = models.EmailField(max_length=100)
      website = models.URLField(max_length=250)
      photo = models.FileField()
      small_photo = models.FileField()
      description = models.TextField()
      recommended_by = models.ForeignKey(TestUser,
      on_delete=models.CASCADE)
      my_projects = models.ManyToManyField(Prem_PhotoGallery,
      Prem_PDF,
      Prem_YouTube,
      Prem_VilmVeo,
      Prem_Audio,
      Prem_Website,
      Prem_SocialMedia,
      Prem_GoogleMaps,
      blank=True)
      keywords = models.TextField()
      trade = models.ManyToManyField(Trade)

      #premium
      premium_accounts = models.BooleanField(default=False)

      #location
      city = models.CharField(max_length=100)
      street = models.CharField(max_length=100)
      zip_code = models.CharField(max_length=8)

      #data joined
      time_create_account = models.DateTimeField()









      share|improve this question














      I created the models.py file and when I try to execute the 'makemigrations' command, I get the following error:



          return bool(self.related_name) and self.related_name[-1] == '+'
      TypeError: 'ModelBase' object does not support indexing


      I tried to find a forum reply, but the topics mainly concern the error that appears from the views.py file. In my situations, this file has not been created yet.



      Any help will be appreciated, also about the more transparent code in the database.



      My models.py



      from django.db import models


      #additives
      class TestUser(models.Model):
      name = models.CharField(max_length=50)

      class Trade(models.Model):
      all_trade_here = models.TextField()

      class ImageGallery(models.Model):
      image = models.ImageField()

      class SocialMediaLinks(models.Model):
      link = models.URLField()

      # Option for premium user
      class Prem_PhotoGallery(models.Model):
      name_photo_gallery = models.CharField(max_length=50)
      image_gallery = models.ForeignKey(ImageGallery,
      on_delete=models.CASCADE)

      class Prem_PDF(models.Model):
      name_pdf = models.CharField(max_length=50)
      file = models.FileField()

      class Prem_YouTube(models.Model):
      name_youtube = models.CharField(max_length=50)
      link = models.URLField()

      class Prem_VilmVeo(models.Model):
      name_vilmveo = models.CharField(max_length=50)
      link = models.URLField()

      class Prem_Audio(models.Model):
      name_audio = models.CharField(max_length=50)
      link = models.URLField()

      class Prem_Website(models.Model):
      name_website = models.CharField(max_length=50)
      link = models.URLField()

      class Prem_SocialMedia(models.Model):
      name_social_button_1 = models.CharField(max_length=50)
      links = models.ForeignKey(SocialMediaLinks, on_delete=models.CASCADE)

      class Prem_GoogleMaps(models.Model):
      name_google_maps = models.CharField(max_length=50)
      link = models.URLField()

      # element write by user
      class Person(models.Model):
      #basic information, all write user
      name = models.CharField(max_length=100)
      surname = models.CharField(max_length=100)
      phone = models.CharField(max_length=15)
      e_mail = models.EmailField(max_length=100)
      website = models.URLField(max_length=250)
      photo = models.FileField()
      small_photo = models.FileField()
      description = models.TextField()
      recommended_by = models.ForeignKey(TestUser,
      on_delete=models.CASCADE)
      my_projects = models.ManyToManyField(Prem_PhotoGallery,
      Prem_PDF,
      Prem_YouTube,
      Prem_VilmVeo,
      Prem_Audio,
      Prem_Website,
      Prem_SocialMedia,
      Prem_GoogleMaps,
      blank=True)
      keywords = models.TextField()
      trade = models.ManyToManyField(Trade)

      #premium
      premium_accounts = models.BooleanField(default=False)

      #location
      city = models.CharField(max_length=100)
      street = models.CharField(max_length=100)
      zip_code = models.CharField(max_length=8)

      #data joined
      time_create_account = models.DateTimeField()






      django sqlite model






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 11:03









      Maddie GrahamMaddie Graham

      245113




      245113
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Your ManyToManyField configuration for my_projects is not correct. A ManyToManyField takes a single class as it's first positional argument. It can also accept other optional arguments such as related_name.



          You have passed multiple classes as arguments. ManyToManyField would thus assume that these other classes correspond to the values for the optional arguments, causing the error you're seeing.



          You would need to separate my_projects into separate ManyToManyFields:



          my_photogalleries = models.ManyToManyField(Prem_PhotoGallery)
          my_pdfs = models.ManyToManyField(Prem_PDF)
          ... etc ...





          share|improve this answer

























            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%2f53318018%2ftypeerror-modelbase-object-does-not-support-indexing%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









            1














            Your ManyToManyField configuration for my_projects is not correct. A ManyToManyField takes a single class as it's first positional argument. It can also accept other optional arguments such as related_name.



            You have passed multiple classes as arguments. ManyToManyField would thus assume that these other classes correspond to the values for the optional arguments, causing the error you're seeing.



            You would need to separate my_projects into separate ManyToManyFields:



            my_photogalleries = models.ManyToManyField(Prem_PhotoGallery)
            my_pdfs = models.ManyToManyField(Prem_PDF)
            ... etc ...





            share|improve this answer






























              1














              Your ManyToManyField configuration for my_projects is not correct. A ManyToManyField takes a single class as it's first positional argument. It can also accept other optional arguments such as related_name.



              You have passed multiple classes as arguments. ManyToManyField would thus assume that these other classes correspond to the values for the optional arguments, causing the error you're seeing.



              You would need to separate my_projects into separate ManyToManyFields:



              my_photogalleries = models.ManyToManyField(Prem_PhotoGallery)
              my_pdfs = models.ManyToManyField(Prem_PDF)
              ... etc ...





              share|improve this answer




























                1












                1








                1







                Your ManyToManyField configuration for my_projects is not correct. A ManyToManyField takes a single class as it's first positional argument. It can also accept other optional arguments such as related_name.



                You have passed multiple classes as arguments. ManyToManyField would thus assume that these other classes correspond to the values for the optional arguments, causing the error you're seeing.



                You would need to separate my_projects into separate ManyToManyFields:



                my_photogalleries = models.ManyToManyField(Prem_PhotoGallery)
                my_pdfs = models.ManyToManyField(Prem_PDF)
                ... etc ...





                share|improve this answer















                Your ManyToManyField configuration for my_projects is not correct. A ManyToManyField takes a single class as it's first positional argument. It can also accept other optional arguments such as related_name.



                You have passed multiple classes as arguments. ManyToManyField would thus assume that these other classes correspond to the values for the optional arguments, causing the error you're seeing.



                You would need to separate my_projects into separate ManyToManyFields:



                my_photogalleries = models.ManyToManyField(Prem_PhotoGallery)
                my_pdfs = models.ManyToManyField(Prem_PDF)
                ... etc ...






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 15 '18 at 16:09

























                answered Nov 15 '18 at 16:02









                Will KeelingWill Keeling

                12k22635




                12k22635
































                    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%2f53318018%2ftypeerror-modelbase-object-does-not-support-indexing%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

                    Bressuire

                    Vorschmack

                    Quarantine