Home > Mobile >  ChoiceField is appearing Instead of CharField in Django Admin Panel
ChoiceField is appearing Instead of CharField in Django Admin Panel

Time:08-28

while creating many-to-one relationship in django using Foreignkey Choicefield is appearing instead of CharField in Django Admin Panel

Image of Model

Image of 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)

CodePudding user response:

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