diff --git a/apps/course/admin/participant.py b/apps/course/admin/participant.py index 641d335..50a0aae 100644 --- a/apps/course/admin/participant.py +++ b/apps/course/admin/participant.py @@ -26,7 +26,7 @@ class ParticipantAdmin(admin.ModelAdmin): 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'].queryset = StudentUser.objects.filter(user_type=User.UserType.STUDENT) form.base_fields['student'].widget.can_add_related = True # فعال کردن دکمه اضافه کردن return form diff --git a/apps/course/migrations/0006_auto_20250113_1337.py b/apps/course/migrations/0006_auto_20250113_1337.py new file mode 100644 index 0000000..f6e31be --- /dev/null +++ b/apps/course/migrations/0006_auto_20250113_1337.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.7 on 2025-01-13 13:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('course', '0005_participant_unread_messages_count'), + ] + + operations = [ + migrations.AlterField( + model_name='lesson', + name='content_type', + field=models.CharField(choices=[('youtube_link', 'Youtube Link'), ('video_file', 'Video File'), ('audio_file', 'Audio File')], max_length=50, verbose_name='Content Type'), + ), + migrations.AlterField( + model_name='lesson', + name='video_link', + field=models.CharField(blank=True, max_length=500, null=True, verbose_name='Link'), + ), + ] diff --git a/apps/course/models/lesson.py b/apps/course/models/lesson.py index 64b9d4f..d300dfc 100644 --- a/apps/course/models/lesson.py +++ b/apps/course/models/lesson.py @@ -16,21 +16,22 @@ def lesson_file_upload_to(instance, filename): class Lesson(models.Model): class ContentTypeChoices(models.TextChoices): - LINK = 'link', 'Link' - FILE = 'file', 'File' + YOUTUBE_LINK = 'youtube_link', 'Youtube Link' + VIDEO_FILE = 'video_file', 'Video File' + AUDIO_FILE = 'audio_file', 'Audio File' course = models.ForeignKey("course.Course", on_delete=models.CASCADE, related_name='lessons', verbose_name='Course') title = models.CharField(max_length=255, verbose_name='Lesson Title') priority = models.IntegerField(null=True, blank=True, verbose_name='Priority') is_active = models.BooleanField(default=True, verbose_name=_('Is Active')) duration = models.PositiveIntegerField(verbose_name='Duration (in minutes)') - content_type = models.CharField(max_length=10, choices=ContentTypeChoices.choices, verbose_name='Content Type') + content_type = models.CharField(max_length=50, choices=ContentTypeChoices.choices, verbose_name='Content Type') content_file = models.FileField( null=True, blank=True, upload_to=lesson_file_upload_to, ) - video_link = models.CharField(max_length=500, null=True, blank=True, verbose_name='Video Link') + video_link = models.CharField(max_length=500, null=True, blank=True, verbose_name='Link') created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Created at")) updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated At")) diff --git a/apps/course/views/lesson.py b/apps/course/views/lesson.py index 9941f93..7492fa1 100644 --- a/apps/course/views/lesson.py +++ b/apps/course/views/lesson.py @@ -86,6 +86,22 @@ class LessonDetailView(RetrieveAPIView): class LessonCompletionCreateAPIView(GenericAPIView): permission_classes = [IsAuthenticated] + + @swagger_auto_schema( + request_body=openapi.Schema( + type=openapi.TYPE_OBJECT, + required=['lesson_id'], + properties={ + 'lesson_id': openapi.Schema(type=openapi.TYPE_INTEGER, description='ID of the lesson to be marked as completed'), + }, + ), + responses={ + 201: 'Lesson completed successfully.', + 200: 'Lesson already completed.', + 400: 'Lesson ID is required.', + 404: 'Lesson not found.', + } + ) def post(self, request): student = request.user # Assuming the user is the student lesson_id = request.data.get('lesson_id')