Related Field got invalid lookup: icontains - Django 2.1Can't add field to ModelForm at __init__Show information of subclass in list_display djangoDjango FieldError at /admin/app/modelClass/How to expose some specific fields of model_b based on a field of model_a?django admin related Field got invalid lookup: icontainsDjango: `Related Field got invalid lookup: icontains`How to define Mode with generic ForeignKey in DjangoHow to remove Django redundant inner joinHow to display multiple objects from fields in Django AdminSchool attendence model
Does detail obscure or enhance action?
Why can't I see bouncing of a switch on an oscilloscope?
What defenses are there against being summoned by the Gate spell?
Important Resources for Dark Age Civilizations?
Did Shadowfax go to Valinor?
Is it possible to run Internet Explorer on OS X El Capitan?
Watching something be written to a file live with tail
How can I make my BBEG immortal short of making them a Lich or Vampire?
How old can references or sources in a thesis be?
RSA: Danger of using p to create q
What are these boxed doors outside store fronts in New York?
A case of the sniffles
Do I have a twin with permutated remainders?
What does it mean to describe someone as a butt steak?
How to format long polynomial?
How does quantile regression compare to logistic regression with the variable split at the quantile?
Today is the Center
Is it legal for company to use my work email to pretend I still work there?
Arrow those variables!
Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?
LWC SFDX source push error TypeError: LWC1009: decl.moveTo is not a function
Modeling an IP Address
Can a Cauchy sequence converge for one metric while not converging for another?
Is it possible to do 50 km distance without any previous training?
Related Field got invalid lookup: icontains - Django 2.1
Can't add field to ModelForm at __init__Show information of subclass in list_display djangoDjango FieldError at /admin/app/modelClass/How to expose some specific fields of model_b based on a field of model_a?django admin related Field got invalid lookup: icontainsDjango: `Related Field got invalid lookup: icontains`How to define Mode with generic ForeignKey in DjangoHow to remove Django redundant inner joinHow to display multiple objects from fields in Django AdminSchool attendence model
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to make the "vanKit" field searchable in my admin page. "vanKit" is a ForeignKey and whenever I add it it my search_fields list it gives me this error "Related Field got invalid lookup: icontains". Here's my code:
Models.py
class KitSupplies(models.Model):
supplyName = models.ForeignKey(supplies, on_delete=models.CASCADE)
vanKit = models.ForeignKey(van_kit, on_delete=models.CASCADE)
quantity = models.PositiveSmallIntegerField(blank=False)
def __str__(self):
return str(self.supplyName)
class Meta:
verbose_name_plural = 'Kit Supplies'
admin.py
class KitSuppliesAdmin(admin.ModelAdmin):
list_display = ('supplyName', 'vanKit', 'quantity')
search_fields = ['vanKit']
admin.site.register(KitSupplies, KitSuppliesAdmin)
I tried to use search_fields = ['vanKit__name']
like the other stack overflow answers suggested but that did not work for me. Can anyone explain why I am getting this error and how to get around it? I am using Django 2.1 and python 3.7. Thanks in advance!
django python-3.x django-models
add a comment |
I am trying to make the "vanKit" field searchable in my admin page. "vanKit" is a ForeignKey and whenever I add it it my search_fields list it gives me this error "Related Field got invalid lookup: icontains". Here's my code:
Models.py
class KitSupplies(models.Model):
supplyName = models.ForeignKey(supplies, on_delete=models.CASCADE)
vanKit = models.ForeignKey(van_kit, on_delete=models.CASCADE)
quantity = models.PositiveSmallIntegerField(blank=False)
def __str__(self):
return str(self.supplyName)
class Meta:
verbose_name_plural = 'Kit Supplies'
admin.py
class KitSuppliesAdmin(admin.ModelAdmin):
list_display = ('supplyName', 'vanKit', 'quantity')
search_fields = ['vanKit']
admin.site.register(KitSupplies, KitSuppliesAdmin)
I tried to use search_fields = ['vanKit__name']
like the other stack overflow answers suggested but that did not work for me. Can anyone explain why I am getting this error and how to get around it? I am using Django 2.1 and python 3.7. Thanks in advance!
django python-3.x django-models
1
What does the vanKit model look like? Are you sureVanKit.name
is a string field?
– farooq
Mar 9 at 1:14
Isvan_kit
andsupplies
your class name?why notVanKit
andSupply
? See: docs.python-guide.org/writing/style
– Waket Zheng
Mar 9 at 3:39
vanKit is a foreign key to van_kit. The name of the van kits are specified by " van_kit_name = models.CharField(max_length=100)" in the van_kit class
– Tank12
Mar 9 at 7:40
I'll make those changes to correct the class names as well
– Tank12
Mar 9 at 7:41
add a comment |
I am trying to make the "vanKit" field searchable in my admin page. "vanKit" is a ForeignKey and whenever I add it it my search_fields list it gives me this error "Related Field got invalid lookup: icontains". Here's my code:
Models.py
class KitSupplies(models.Model):
supplyName = models.ForeignKey(supplies, on_delete=models.CASCADE)
vanKit = models.ForeignKey(van_kit, on_delete=models.CASCADE)
quantity = models.PositiveSmallIntegerField(blank=False)
def __str__(self):
return str(self.supplyName)
class Meta:
verbose_name_plural = 'Kit Supplies'
admin.py
class KitSuppliesAdmin(admin.ModelAdmin):
list_display = ('supplyName', 'vanKit', 'quantity')
search_fields = ['vanKit']
admin.site.register(KitSupplies, KitSuppliesAdmin)
I tried to use search_fields = ['vanKit__name']
like the other stack overflow answers suggested but that did not work for me. Can anyone explain why I am getting this error and how to get around it? I am using Django 2.1 and python 3.7. Thanks in advance!
django python-3.x django-models
I am trying to make the "vanKit" field searchable in my admin page. "vanKit" is a ForeignKey and whenever I add it it my search_fields list it gives me this error "Related Field got invalid lookup: icontains". Here's my code:
Models.py
class KitSupplies(models.Model):
supplyName = models.ForeignKey(supplies, on_delete=models.CASCADE)
vanKit = models.ForeignKey(van_kit, on_delete=models.CASCADE)
quantity = models.PositiveSmallIntegerField(blank=False)
def __str__(self):
return str(self.supplyName)
class Meta:
verbose_name_plural = 'Kit Supplies'
admin.py
class KitSuppliesAdmin(admin.ModelAdmin):
list_display = ('supplyName', 'vanKit', 'quantity')
search_fields = ['vanKit']
admin.site.register(KitSupplies, KitSuppliesAdmin)
I tried to use search_fields = ['vanKit__name']
like the other stack overflow answers suggested but that did not work for me. Can anyone explain why I am getting this error and how to get around it? I am using Django 2.1 and python 3.7. Thanks in advance!
django python-3.x django-models
django python-3.x django-models
asked Mar 9 at 1:01
Tank12Tank12
216
216
1
What does the vanKit model look like? Are you sureVanKit.name
is a string field?
– farooq
Mar 9 at 1:14
Isvan_kit
andsupplies
your class name?why notVanKit
andSupply
? See: docs.python-guide.org/writing/style
– Waket Zheng
Mar 9 at 3:39
vanKit is a foreign key to van_kit. The name of the van kits are specified by " van_kit_name = models.CharField(max_length=100)" in the van_kit class
– Tank12
Mar 9 at 7:40
I'll make those changes to correct the class names as well
– Tank12
Mar 9 at 7:41
add a comment |
1
What does the vanKit model look like? Are you sureVanKit.name
is a string field?
– farooq
Mar 9 at 1:14
Isvan_kit
andsupplies
your class name?why notVanKit
andSupply
? See: docs.python-guide.org/writing/style
– Waket Zheng
Mar 9 at 3:39
vanKit is a foreign key to van_kit. The name of the van kits are specified by " van_kit_name = models.CharField(max_length=100)" in the van_kit class
– Tank12
Mar 9 at 7:40
I'll make those changes to correct the class names as well
– Tank12
Mar 9 at 7:41
1
1
What does the vanKit model look like? Are you sure
VanKit.name
is a string field?– farooq
Mar 9 at 1:14
What does the vanKit model look like? Are you sure
VanKit.name
is a string field?– farooq
Mar 9 at 1:14
Is
van_kit
and supplies
your class name?why not VanKit
and Supply
? See: docs.python-guide.org/writing/style– Waket Zheng
Mar 9 at 3:39
Is
van_kit
and supplies
your class name?why not VanKit
and Supply
? See: docs.python-guide.org/writing/style– Waket Zheng
Mar 9 at 3:39
vanKit is a foreign key to van_kit. The name of the van kits are specified by " van_kit_name = models.CharField(max_length=100)" in the van_kit class
– Tank12
Mar 9 at 7:40
vanKit is a foreign key to van_kit. The name of the van kits are specified by " van_kit_name = models.CharField(max_length=100)" in the van_kit class
– Tank12
Mar 9 at 7:40
I'll make those changes to correct the class names as well
– Tank12
Mar 9 at 7:41
I'll make those changes to correct the class names as well
– Tank12
Mar 9 at 7:41
add a comment |
1 Answer
1
active
oldest
votes
So I figured it out, I had to use "search_fields = ['vanKit__van_kit_name']" van_kit_name is the field that held the name of the van kits in the van_kit model that "vanKit" relates to through a Foreign Key. I had to access the Char Field that held the van kit's name in the actual van_kit model.
add a comment |
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
);
);
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%2f55072980%2frelated-field-got-invalid-lookup-icontains-django-2-1%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
So I figured it out, I had to use "search_fields = ['vanKit__van_kit_name']" van_kit_name is the field that held the name of the van kits in the van_kit model that "vanKit" relates to through a Foreign Key. I had to access the Char Field that held the van kit's name in the actual van_kit model.
add a comment |
So I figured it out, I had to use "search_fields = ['vanKit__van_kit_name']" van_kit_name is the field that held the name of the van kits in the van_kit model that "vanKit" relates to through a Foreign Key. I had to access the Char Field that held the van kit's name in the actual van_kit model.
add a comment |
So I figured it out, I had to use "search_fields = ['vanKit__van_kit_name']" van_kit_name is the field that held the name of the van kits in the van_kit model that "vanKit" relates to through a Foreign Key. I had to access the Char Field that held the van kit's name in the actual van_kit model.
So I figured it out, I had to use "search_fields = ['vanKit__van_kit_name']" van_kit_name is the field that held the name of the van kits in the van_kit model that "vanKit" relates to through a Foreign Key. I had to access the Char Field that held the van kit's name in the actual van_kit model.
answered Mar 9 at 7:56
Tank12Tank12
216
216
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.
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%2f55072980%2frelated-field-got-invalid-lookup-icontains-django-2-1%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
1
What does the vanKit model look like? Are you sure
VanKit.name
is a string field?– farooq
Mar 9 at 1:14
Is
van_kit
andsupplies
your class name?why notVanKit
andSupply
? See: docs.python-guide.org/writing/style– Waket Zheng
Mar 9 at 3:39
vanKit is a foreign key to van_kit. The name of the van kits are specified by " van_kit_name = models.CharField(max_length=100)" in the van_kit class
– Tank12
Mar 9 at 7:40
I'll make those changes to correct the class names as well
– Tank12
Mar 9 at 7:41