简体   繁体   中英

ChoiceField is appearing Instead of CharField in Django Admin Panel

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM