این کد رو طوری بنویس که علاوه بر اینکه میتونم از مقادیر لیست شده انتخاب کنم بتونم دستی هم مقدار بدم و همچنین در پنل ادمین وقتی رکورد ها رو در پنل ادمین نمایش میده بجا اینکه شماره تخصص ها رو بنویسه اسم اونا رو بنویسه
from django.db import models
from multiselectfield import MultiSelectField
from django.conf import settings
from app_medicalCenters.models import MedicalCenterInfo



class Specialty(models.Model):
    name = models.CharField(
        max_length=100, 
        unique=True, 
        verbose_name="تخصص"
    )

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'tbl_doctor_specialties'
        verbose_name_plural = 'تخصص‌های پزشکی'


class University(models.Model):
    name = models.CharField(
        max_length=100, 
        unique=True, 
        verbose_name="نام دانشگاه"
    )

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'tbl_doctor_universities'
        verbose_name_plural = 'دانشگاه‌های پزشکی'


class Degree(models.Model):
    name = models.CharField(
        max_length=100, 
        unique=True, 
        verbose_name="مقطع تحصیلی"
    )

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'tbl_doctor_degrees'
        verbose_name_plural = 'مدارج تحصیلی'


class DoctorsDatabase(models.Model):
    medical_id = models.CharField(
        max_length=40, 
        primary_key=True, 
        verbose_name="شماره نظام پزشکی"
    )
    first_name = models.CharField(
        max_length=30, 
        blank=True, 
        null=True, 
        verbose_name="نام"
    )
    last_name = models.CharField(
        max_length=50, 
        blank=True, 
        null=True, 
        verbose_name="نام خانوادگی"
    )
    specialtie = models.CharField(
        max_length=255, 
        blank=True, 
        null=True, 
        verbose_name="تخصص"
    )
    city = models.CharField(
        max_length=100, 
        blank=True, 
        null=True, 
        verbose_name="شهر"
    )
    degree = models.CharField(
        max_length=100, 
        blank=True, 
        null=True, 
        verbose_name="مدرک تحصیلی"
    )

    def __str__(self):
        return f"{self.first_name} {self.last_name} نظام پزشکی: {self.medical_id}"

    class Meta:
        db_table = 'tbl_doctor_database'
        verbose_name_plural = 'پایگاه داده پزشکان'


class DoctorsInfo(models.Model):
    specialties_choices = Specialty.objects.values_list('id', 'name')
    medical_centers_choices = MedicalCenterInfo.objects.values_list('id', 'name_medical_center')
    # def get_specialty_choices():
    #     return [specialty.name for specialty in Specialty.objects.all()]
    # def get_specialties(self, obj):
    #     return [specialty.name for specialty in obj.Specialty.all()]

    user = models.OneToOneField(
        settings.AUTH_USER_MODEL, 
        on_delete=models.CASCADE, 
        verbose_name="کاربر"
    )
    specialties = MultiSelectField(
        choices=specialties_choices, 
        blank=True, 
        verbose_name="تخصص‌ها"
    )
    university = models.CharField(
        max_length=255,
        blank=True, 
        null=True, 
        verbose_name="فارغ‌التحصیل"
    )
    degree = models.CharField(
        max_length=255,
        blank=True,
        null=True, 
        verbose_name="مدرک تحصیلی"
    )
    profile_image = models.ImageField(
        upload_to='app_doctors/profile_image/', 
        blank=True, 
        null=True, 
        verbose_name='تصویر پروفایل پزشک'
    )
    introduction_video = models.FileField(
        upload_to='app_doctors/introduction_video/', 
        blank=True, 
        null=True,
        verbose_name='ویدیو معرفی پزشک'
    )
    office_location = models.CharField(
        max_length=15, 
        blank=True, 
        null=True, 
        verbose_name='لوکیشن مطب'
    )
    resume = models.TextField(
        blank=True, 
        null=True, 
        verbose_name='رزومه'
    )
    description = models.TextField(
        blank=True, 
        null=True, 
        verbose_name='توضیحات'
    )
    name_medical_centers = MultiSelectField(
        choices=medical_centers_choices,
        blank=True, 
        verbose_name="فعالیت در مراکز درمانی"
    )
    

    def __str__(self):
        return f"{self.user.first_name} {self.user.last_name}"

    class Meta:
        db_table = 'tbl_doctor_info'
        verbose_name_plural = 'اطلاعات پزشک'





from django import forms
from django_select2 import forms as s2forms
from django_select2.forms import Select2MultipleWidget
from .models import DoctorsInfo, Specialty
from app_medicalCenters.models import MedicalCenterInfo
# from django.forms.widgets import CheckboxSelectMultiple

class DoctorsInfoForm(forms.ModelForm):
    university = forms.CharField(
        widget=forms.TextInput(attrs={'list': 'university-list'})
    )
    degree = forms.CharField(
        widget=forms.TextInput(attrs={'list': 'degree-list'})
    )
    specialties = s2forms.ModelSelect2MultipleWidget(
        queryset=Specialty.objects.all(),
        widget=Select2MultipleWidget,
        required=False
    )
    name_medical_centers = s2forms.ModelSelect2MultipleWidget(
        queryset=MedicalCenterInfo.objects.all(),
        widget=Select2MultipleWidget,
        required=False
    )

    class Meta:
        model = DoctorsInfo
        fields = '__all__'
        widgets = {
            'specialties': Select2MultipleWidget,
            'name_medical_centers': Select2MultipleWidget,
        }
        
    class Media:
        css = {
            'all': ('app_doctors/css/custom_select2.css',) 
        }

from django.contrib import admin
from .models import Specialty, University, Degree, DoctorsInfo
from .forms import DoctorsInfoForm
from app_medicalCenters.models import MedicalCenterInfo


@admin.register(Specialty)
class SpecialtyAdmin(admin.ModelAdmin):
    list_display = ('name',)
    search_fields = ('name',)


@admin.register(University)
class UniversityAdmin(admin.ModelAdmin):
    list_display = ('name',)
    search_fields = ('name',)


@admin.register(Degree)
class DegreeAdmin(admin.ModelAdmin):
    list_display = ('name',)
    search_fields = ('name',)

@admin.register(DoctorsInfo)
class DoctorsInfoAdmin(admin.ModelAdmin):
    form = DoctorsInfoForm
    list_display = ( 'get_user_full_name', 'university', 'degree', 'specialties', 'name_medical_centers')
    search_fields = ('user__first_name', 'user__last_name', 'specialties', 'university', 'degree')
    # raw_id_fields = ('user', )
    autocomplete_fields = ('user', )
    

    def get_extra_context(self, request):
        return {
            'university_list': list(University.objects.values_list('name', flat=True)),
            'degree_list': list(Degree.objects.values_list('name', flat=True)),
            'specialty_list': list(Specialty.objects.values_list('name', flat=True)),
            'name_medical_centers': list(MedicalCenterInfo.objects.values_list('name_medical_center', flat=True)),
        }

    def add_view(self, request, form_url='', extra_context=None):
        extra_context = extra_context or {}
        extra_context.update(self.get_extra_context(request))
        return super().add_view(request, form_url, extra_context=extra_context)

    def change_view(self, request, object_id, form_url='', extra_context=None):
        extra_context = extra_context or {}
        extra_context.update(self.get_extra_context(request))
        return super().change_view(request, object_id, form_url, extra_context=extra_context)
    
    def get_user_full_name(self, obj):
        return f"{obj.user.first_name} {obj.user.last_name}"
    get_user_full_name.short_description = 'نام پزشک'

    # def get_specialties(self, obj):
    #     return ", ".join([specialty.name for specialty in obj.Specialty.all()])
    # get_specialties.short_description = 'تخصص‌ها'