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

            Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

            Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

            How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page