Issue
while creating many-to-one relationship in django using Foreignkey Choicefield is appearing instead of CharField in Django Admin Panel
Code of Views.py
from django.http import JsonResponse
from .models import Name
def names_list(request):
MAX_OBJECTS = 1
name = Name.objects.all()
data = {"results": list(name.values("Name"))}
return JsonResponse(data)
Solution
Django admin panel is showing the intended dropdown selection list.
Origin is basically a foreign key of Country model. In the Django admin panel, foreign key fields are displayed as dropdown lists.
If you want to add countries you might need to
- Add Country model in Django admin site
- Open Django admin, click on country model and populate data
- Later this data will be available for reference in Name's model
- Where you can add Name and select country.
Answered By - Abdullah Mughal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.