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;








1















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!










share|improve this question

















  • 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 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











  • I'll make those changes to correct the class names as well

    – Tank12
    Mar 9 at 7:41

















1















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!










share|improve this question

















  • 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 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











  • I'll make those changes to correct the class names as well

    – Tank12
    Mar 9 at 7:41













1












1








1








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!










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 9 at 1:01









Tank12Tank12

216




216







  • 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 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











  • I'll make those changes to correct the class names as well

    – Tank12
    Mar 9 at 7:41












  • 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 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











  • 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












1 Answer
1






active

oldest

votes


















1














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.






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%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









    1














    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.






    share|improve this answer



























      1














      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.






      share|improve this answer

























        1












        1








        1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 9 at 7:56









        Tank12Tank12

        216




        216





























            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%2f55072980%2frelated-field-got-invalid-lookup-icontains-django-2-1%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

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme