i created this to make searchbox to search models, when i replace body instead of author it works perfectly and fetches data accurately but when i use foreign key object string input is not working but when i type pk of user it fetches the username accurately but does not accept string for eg: when i type name of the post it gets but on author when i type name of the author it says following error and does not accept string but can accept pk and fetch author
pls edit this code such that when i type name of the author it gets the name and their post
HELP IS MUCH APPRECIATED
views.py
def search(request):
query = request.GET['query']
allposts = bio.objects.filter(author=query)
params = {'allposts':allposts}
return render(request,'profile_app/search.html',params)
models.py
class bio(models.Model):
author = models.ForeignKey(User,on_delete=models.CASCADE)
body = models.CharField(max_length=50)
search.html
<h1>this is home</h1>
<form action="/search" method="get">
<input type="search" name="query">
<button type="submit">press here</button>
</form>
question from:
https://stackoverflow.com/questions/65857311/field-id-expected-a-number-but-got-admin-in-django 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…