How to do it ?

14 views
Skip to first unread message

Ivan Goncalves

unread,
Feb 20, 2014, 4:19:50 PM2/20/14
to django-e...@googlegroups.com
I need to do a search in related fields in Django Admin, as below:

Suppose I have these 2 models in the models.py:

class business(models.Model):
    name=models.CharField(max_length=40, blank=True, null=True)
    
class phone(models.Model):
    business=models.ForeignKey(business, verbose_name='Business',blank=False)    
    number=models.CharField(max_length=40, blank=True, null=True)


And in the admin.py i have:

class businessAdmin(admin.ModelAdmin):
    model=business
    search_fields = phone__number

    **  How do we make this search work? Ie, bring me all companies that possess the phone number entered by the User. ??? **

    


Andy Baker

unread,
Feb 21, 2014, 3:54:38 AM2/21/14
to django-e...@googlegroups.com
I think you're posting in the wrong forum. This forum concerns a specific add-on to Django - not Django itself.


However - in answer to your question this should work: search_fields = [phone__number]

Andy Baker

unread,
Feb 21, 2014, 3:55:20 AM2/21/14
to django-e...@googlegroups.com
Sorry. Forgot the quotes: search_fields = ['phone__number']
Reply all
Reply to author
Forward
0 new messages