Browse Source

feat lession

master
alireza 1 year ago
parent
commit
9f88489558
  1. 2
      apps/course/admin/participant.py
  2. 23
      apps/course/migrations/0006_auto_20250113_1337.py
  3. 9
      apps/course/models/lesson.py
  4. 16
      apps/course/views/lesson.py

2
apps/course/admin/participant.py

@ -26,7 +26,7 @@ class ParticipantAdmin(admin.ModelAdmin):
form = super().get_form(request, obj, **kwargs) form = super().get_form(request, obj, **kwargs)
if obj is None: # Adding a new participant if obj is None: # Adding a new participant
# محدود کردن انتخاب دانش‌آموزان به کاربرانی که از نوع StudentUser هستند # محدود کردن انتخاب دانش‌آموزان به کاربرانی که از نوع 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 # فعال کردن دکمه اضافه کردن form.base_fields['student'].widget.can_add_related = True # فعال کردن دکمه اضافه کردن
return form return form

23
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'),
),
]

9
apps/course/models/lesson.py

@ -16,21 +16,22 @@ def lesson_file_upload_to(instance, filename):
class Lesson(models.Model): class Lesson(models.Model):
class ContentTypeChoices(models.TextChoices): 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') 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') title = models.CharField(max_length=255, verbose_name='Lesson Title')
priority = models.IntegerField(null=True, blank=True, verbose_name='Priority') priority = models.IntegerField(null=True, blank=True, verbose_name='Priority')
is_active = models.BooleanField(default=True, verbose_name=_('Is Active')) is_active = models.BooleanField(default=True, verbose_name=_('Is Active'))
duration = models.PositiveIntegerField(verbose_name='Duration (in minutes)') 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( content_file = models.FileField(
null=True, null=True,
blank=True, blank=True,
upload_to=lesson_file_upload_to, 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")) created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Created at"))
updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated At")) updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated At"))

16
apps/course/views/lesson.py

@ -86,6 +86,22 @@ class LessonDetailView(RetrieveAPIView):
class LessonCompletionCreateAPIView(GenericAPIView): class LessonCompletionCreateAPIView(GenericAPIView):
permission_classes = [IsAuthenticated] 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): def post(self, request):
student = request.user # Assuming the user is the student student = request.user # Assuming the user is the student
lesson_id = request.data.get('lesson_id') lesson_id = request.data.get('lesson_id')

Loading…
Cancel
Save