TypeError: 'ModelBase' object does not support indexing.
up vote
1
down vote
favorite
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
add a comment |
up vote
1
down vote
favorite
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
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
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
django sqlite model
asked Nov 15 at 11:03
Maddie Graham
143112
143112
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
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 ManyToManyField
s:
my_photogalleries = models.ManyToManyField(Prem_PhotoGallery)
my_pdfs = models.ManyToManyField(Prem_PDF)
... etc ...
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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 ManyToManyField
s:
my_photogalleries = models.ManyToManyField(Prem_PhotoGallery)
my_pdfs = models.ManyToManyField(Prem_PDF)
... etc ...
add a comment |
up vote
1
down vote
accepted
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 ManyToManyField
s:
my_photogalleries = models.ManyToManyField(Prem_PhotoGallery)
my_pdfs = models.ManyToManyField(Prem_PDF)
... etc ...
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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 ManyToManyField
s:
my_photogalleries = models.ManyToManyField(Prem_PhotoGallery)
my_pdfs = models.ManyToManyField(Prem_PDF)
... etc ...
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 ManyToManyField
s:
my_photogalleries = models.ManyToManyField(Prem_PhotoGallery)
my_pdfs = models.ManyToManyField(Prem_PDF)
... etc ...
edited Nov 15 at 16:09
answered Nov 15 at 16:02
Will Keeling
10.4k22329
10.4k22329
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
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%2f53318018%2ftypeerror-modelbase-object-does-not-support-indexing%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