You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
1.3 KiB

# from django.contrib import admin
# from apps.course.models import Participant
# from apps.account.models import StudentUser, User
# @admin.register(Participant)
# class ParticipantAdmin(admin.ModelAdmin):
# list_display = ('student', 'course', 'joined_date', 'unread_messages_count')
# search_fields = ('student__fullname', 'student__email', 'course__title')
# list_filter = ('course', 'joined_date')
# ordering = ('-joined_date',)
# autocomplete_fields = ['student',] # جستجوی پویا برای فیلد دانش‌آموز
# def get_readonly_fields(self, request, obj=None):
# """
# Make fields readonly if the object already exists.
# """
# if obj:
# return ['student', 'course', 'joined_date']
# return []
# def get_form(self, request, obj=None, **kwargs):
# form = super().get_form(request, obj, **kwargs)
# if obj is None: # Adding a new participant
# # محدود کردن انتخاب دانش‌آموزان به کاربرانی که از نوع StudentUser هستند
# # form.base_fields['student'].queryset = StudentUser.objects.filter(user_type=User.UserType.STUDENT)
# form.base_fields['student'].widget.can_add_related = True # فعال کردن دکمه اضافه کردن
# return form