show all materials,assignments requested by tutors and submitted by students in toggle activity history in admin html with the name of person who did the action and when (i already did that on courses with name of person who created course and time of creation) views.py "from django.shortcuts import render, HttpResponse, redirect, get_object_or_404
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.utils import timezone
from .models import InteractionHistory, UserProfile, Course, CourseMaterial, Material, Assignment, Submission, Grade,Enrollment
from django.contrib.auth.decorators import user_passes_test
from django.http import JsonResponse
from django.template.loader import render_to_string
from django.contrib import messages  # Import messages for displaying messages in the template
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from .serializers import CourseSerializer, MaterialSerializer, AssignmentSerializer, SubmissionSerializer, GradeSerializer, InteractionHistorySerializer,TestSerializer, ChapterSerializer, AttendanceSerializer, EnrollmentSerializer, ReadingStateSerializer
from django.contrib import messages  # Import messages for displaying messages in the template
from django import forms



#AUTHENTIFICATION
class SignupForm(forms.Form):
    username = forms.CharField(max_length=30)
    email = forms.EmailField()
    password1 = forms.CharField(widget=forms.PasswordInput)
    password2 = forms.CharField(widget=forms.PasswordInput)
    role = forms.CharField()
    
    def clean_password2(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        if password1 and password2 and password1 != password2:
            raise forms.ValidationError('Passwords do not match.')

        return password2
def SignupPage(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)

        if form.is_valid():
            uname = form.cleaned_data['username']
            email = form.cleaned_data['email']
            pass1 = form.cleaned_data['password1']
            pass2 = form.cleaned_data['password2']
            role = form.cleaned_data['role']

            if pass1 != pass2:
                messages.error(request, "Your password and confirm password are not the same!!")
                return redirect('signup')
            else:
                # Create the user
                my_user = User.objects.create_user(uname, email, pass1)

                # Create the user profile with the assigned role
                UserProfile.objects.create(user=my_user, role=role)

                messages.success(request, "Account created successfully. You can now log in.")
                return redirect('login')
        else:
            messages.error(request, "Invalid input. Please check the form.")
    else:
        form = SignupForm()

    return render(request, 'signup.html', {'form': form})

from django.contrib.auth import authenticate, login

def LoginPage(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password1')  # Use the correct field name

        # Authenticate user
        user = authenticate(request, username=username, password=password)

        if user is not None:
            login(request, user)
            InteractionHistory_history = InteractionHistory.objects.create(student=user, InteractionHistory_type='Login')

            # Print information to the terminal
            print(f"User: {user.username} logged in at {InteractionHistory_history.InteractionHistory_date} from IP {request.META['REMOTE_ADDR']}")

            return redirect('home')
        else:
            messages.error(request, "Invalid username or password")

    return render(request, 'login.html')

@login_required(login_url='login')
def HomePage(request):
    user_role = request.user.userprofile.role

    # Update last login time
    UserProfile.objects.filter(user=request.user).update(last_login=timezone.now())

    if user_role == 'student':
        return redirect('studenthome')
    elif user_role == 'tutor':
        return redirect('tutorhome')
    elif user_role == 'administrator':
        # Fetch InteractionHistory history for administrators
        InteractionHistory_history = InteractionHistory.objects.filter(student=request.user).order_by('-InteractionHistory_date')[:10]

        return redirect('adminhome')
    else:
        return HttpResponse("Invalid user role")

@login_required(login_url='login')
def LogoutPage(request):
    # Update last logout time
    UserProfile.objects.filter(user=request.user).update(last_logout=timezone.now())
    InteractionHistory.objects.create(student=request.user, InteractionHistory_type='Logout')

    logout(request)
    return redirect('login')
#STUDENT PAGE
from django.shortcuts import render
from .models import Assignment

@login_required(login_url='login')
def StudentHomePage(request):
    # Fetch all available courses
    enrolled_courses = request.user.courses.all()
    available_courses = Course.objects.exclude(id__in=enrolled_courses.values_list('id', flat=True))

    # Fetch assignments for the user
    assignments = Assignment.objects.filter(course__in=enrolled_courses)

    # Add a boolean field to each assignment indicating whether it's submitted by the current user
    for assignment in assignments:
        assignment.submitted = assignment.submission_set.filter(student=request.user).exists()

    return render(request, 'studenthome.html', {'enrolled_courses': enrolled_courses, 'available_courses': available_courses, 'assignments': assignments})

@login_required(login_url='login')
def enroll_course(request, course_id):
    course = get_object_or_404(Course, id=course_id)

    # Check if the user is not already enrolled in the course
    if request.user not in course.students.all():
        course.students.add(request.user)
        messages.success(request, f"You have successfully enrolled in {course.name}.")
    else:
        messages.warning(request, f"You are already enrolled in {course.name}.")

    return redirect('studenthome')

@login_required(login_url='login')
def leave_course(request, course_id):
    course = get_object_or_404(Course, id=course_id)

    # Check if the user is enrolled in the course
    if request.user in course.students.all():
        course.students.remove(request.user)
        messages.success(request, f"You have successfully left {course.name}.")
    else:
        messages.warning(request, f"You are not enrolled in {course.name}.")

    return redirect('studenthome')
#TUTOR
@login_required(login_url='login')
# Your view logic
def TutorHomePage(request):
    user = request.user
    submitted_assignments = Submission.objects.filter(assignment__course__tutor=user)

    return render(request, 'tutorhome.html', {'user': user, 'submitted_assignments': submitted_assignments})

@login_required(login_url='login')
def create_course(request):
    if request.method == 'POST':
        course_name = request.POST.get('course_name')

        # Create the course and assign the tutor
        course = Course.objects.create(name=course_name, tutor=request.user)
        # Record the creation time and user who created the course
        course.creation_time = timezone.now()
        course.created_by = request.user
        course.save()
     
        # Redirect to a page where students can see and enroll in courses
        return redirect('tutorhome')

@login_required(login_url='login')
def upload_material(request):
    if request.method == 'POST':
        material_title = request.POST.get('material_title')
        material_file = request.FILES.get('material_file')
        material_course_id = request.POST.get('material_course')

        # Get the course based on the selected ID
        course = Course.objects.get(id=material_course_id)

        

        # Create the material
        CourseMaterial.objects.create(title=material_title, file=material_file, course=course)

        return redirect('tutorhome')

    return render(request, 'upload_material.html') 
@login_required(login_url='login')

def add_chapter(request, course_name):
    if request.method == 'POST':
        chapter_name = request.POST.get('chapter_name')
        course = Course.objects.get(name=course_name, tutor=request.user)
        course.add_chapter(chapter_name)
        return redirect('tutor_home')

    return render(request, 'add_chapter.html', {'course_name': course_name})
def request_assignment(request):
    if request.method == 'POST':
        assignment_title = request.POST.get('assignment_title')
        assignment_description = request.POST.get('assignment_description')
        due_date = request.POST.get('due_date')
        course_id = request.POST.get('course')

        # Get the course based on the selected ID
        course = Course.objects.get(id=course_id)

        # Create the assignment for the specific course
        assignment = Assignment.objects.create(
            title=assignment_title,
            description=assignment_description,
            due_date=due_date,
            course=course,
            status='pending'
        )

        # Get all enrolled students in the course
        enrolled_students = Enrollment.objects.filter(course=course)

        for enrollment in enrolled_students:
            # Assign the created assignment to each student in the course
            assignment.students.add(enrollment.student)

        messages.success(request, 'Assignment requested successfully.')
        
        return redirect('tutorhome')  # Redirect to the tutor's home page after the request is submitted
@login_required(login_url='login')
def request_assignment(request):
    if request.method == 'POST':
        assignment_title = request.POST.get('assignment_title')
        assignment_description = request.POST.get('assignment_description')
        due_date = request.POST.get('due_date')
        course_id = request.POST.get('course')

        # Get the course based on the selected ID
        course = get_object_or_404(Course, id=course_id)

        # Create the assignment for the specific course
        assignment = Assignment.objects.create(
            title=assignment_title,
            description=assignment_description,
            due_date=due_date,
            course=course,
                    
            student=request.user,  # Provide the user creating the assignment as the student

            status='pending'
        )

        # Get all enrolled students in the course
        enrolled_students = Enrollment.objects.filter(course=course)

        for enrollment in enrolled_students:
            # Assign the created assignment to each student in the course
            assignment.students.add(enrollment.student)

        messages.success(request, 'Assignment requested successfully.')

        return redirect('tutorhome')  # Redirect to the tutor's home page after the request is submitted

    # Retrieve the list of courses to display in the form
    available_courses = Course.objects.all()

@login_required(login_url='login')
def view_assignments(request, course_id):
    course = get_object_or_404(Course, id=course_id)
    enrollment = Enrollment.objects.filter(course=course, student=request.user).first()

    if not enrollment:
        return render(request, 'not_enrolled.html')

    assignments = Assignment.objects.filter(course=course, students=request.user)
    return render(request, 'studenthome.html', {'course': course, 'assignments': assignments})

#ADMIN
@login_required(login_url='login')
def AdminHomePage(request):
    # Fetch InteractionHistory history for all users
    InteractionHistory_history_students = InteractionHistory.objects.filter(student__userprofile__role='student').order_by('-InteractionHistory_date')[:10]
    InteractionHistory_history_tutors = InteractionHistory.objects.filter(student__userprofile__role='tutor').order_by('-InteractionHistory_date')[:10]

    # Fetch the list of users excluding administrators
    users = User.objects.exclude(userprofile__role='administrator')

    courses = Course.objects.all()

    print(courses)  # Add this line for debugging
    return render(request, 'adminhome.html', {
        'InteractionHistory_history_students': InteractionHistory_history_students,
        'InteractionHistory_history_tutors': InteractionHistory_history_tutors,
        'users': users,
        'courses': courses,  # Make sure to include courses in the context
    })
@login_required(login_url='login')
@user_passes_test(lambda u: u.userprofile.role == 'administrator', login_url='home')
def manage_roles(request):
    if request.method == 'POST':
        user_id = request.POST.get('user_id')
        role = request.POST.get('role')

        user = get_object_or_404(User, id=user_id)
       
         # Check if the user to change role is not an administrator
        if user.userprofile.role != 'administrator':
            user.userprofile.role = role
            user.userprofile.save()
            messages.success(request, 'User role changed successfully.')
        else:
            messages.error(request, 'Cannot change the role of an administrator.')

    return redirect('adminhome')
@login_required(login_url='login')
@user_passes_test(lambda u: u.userprofile.role == 'administrator', login_url='home')
def delete_user(request, user_id):
    if request.method == 'POST':
        user_to_delete = get_object_or_404(User, id=user_id)

        # Check if the user to be deleted is not an administrator
        if user_to_delete.userprofile.role != 'administrator':
            user_to_delete.delete()
            messages.success(request, 'User deleted successfully.')
        else:
            messages.error(request, 'Cannot delete an administrator.')

    return redirect('adminhome')
@login_required(login_url='login')


@login_required(login_url='login')
@user_passes_test(lambda u: u.userprofile.role == 'administrator', login_url='home')
def modify_course(request, course_id):
    if request.method == 'POST':
        new_course_name = request.POST.get('new_course_name')
        course = get_object_or_404(Course, id=course_id)

        # Modify the course name
        course.name = new_course_name
        course.save()

        messages.success(request, 'Course name modified successfully.')

    return redirect('adminhome')

@login_required(login_url='login')
@user_passes_test(lambda u: u.userprofile.role == 'administrator', login_url='home')
def delete_course(request, course_id):
    if request.method == 'POST':
        course_to_delete = get_object_or_404(Course, id=course_id)

        # Delete the course
        course_to_delete.delete()

        messages.success(request, 'Course deleted successfully.')

    return redirect('adminhome')
all_assignments = Assignment.objects.all()

@login_required(login_url='login')
# Example view logic
def submit_assignment(request, assignment_id):
    assignment = get_object_or_404(Assignment, id=assignment_id)

    if request.method == 'POST':
        pdf_file = request.FILES.get('pdf_file')
        grade = request.POST.get('grade')

        # Check if the assignment has already been submitted
        if Submission.objects.filter(student=request.user, assignment=assignment).exists():
            messages.warning(request, 'Assignment already submitted.')
            debug_info = 'Assignment already submitted.'
        else:
            submission = Submission.objects.create(
                student=request.user,  # Make sure to set the correct student
                assignment=assignment,
                submission_content=pdf_file,
                submission_date=timezone.now()
            )

            # Remove the assignment from the list of due assignments for the student
            assignment.student = request.user
            assignment.grade = grade
            assignment.save()

            messages.success(request, 'Assignment submitted successfully.')
            return redirect('studenthome')

    else:
        debug_info = ""

    return JsonResponse({'debug_info': debug_info})
@login_required(login_url='login')
def grade_submission(request, submission_id):
    submission = get_object_or_404(Submission, id=submission_id)

    if request.method == 'POST':
        grade = request.POST.get('grade')
        feedback = request.POST.get('feedback')  # Get feedback from the form
        submission.assignment.grade = float(grade) if grade else None
        submission.assignment.feedback = feedback  # Set the feedback for the assignment
        submission.assignment.save()

        messages.success(request, 'Grade and feedback submitted successfully.')

    return redirect('tutorhome')
#REST
@api_view(['GET'])
def course_list(request):
        courses = Course.objects.all()
        serializer = CourseSerializer(courses, many=True)
        return Response(serializer.data)

@api_view(['GET'])
def material_list(request):
        material = CourseMaterial.objects.all()
        serializer = MaterialSerializer(material, many=True)
        return Response(serializer.data)

@api_view(['GET'])
def Test_list(request):
        material = Test.objects.all()
        serializer = TestSerializer(material, many=True)
        return Response(serializer.data)
@api_view(['GET'])
def Chapter_list(request):
        material = Chapter.objects.all()
        serializer = ChapterSerializer(material, many=True)
        return Response(serializer.data)
@api_view(['GET'])
def Attendance_list(request):
        material = Attendance.objects.all()
        serializer = AttendanceSerializer(material, many=True)
        return Response(serializer.data)

@api_view(['GET'])
def Enrollment_list(request):
        material = Enrollment.objects.all()
        serializer = EnrollmentSerializer(material, many=True)
        return Response(serializer.data)

@api_view(['GET'])
def assignment_list(request):
        assignment = Assignment.objects.all()
        serializer = AssignmentSerializer(assignment, many=True)
        return Response(serializer.data)
@api_view(['GET'])
def grade_list(request):
        grade = Grade.objects.all()
        serializer = GradeSerializer(grade, many=True)
        return Response(serializer.data)
@api_view(['GET'])
def InteractionHistory_list(request):
        InteractionHistory = InteractionHistory.objects.all()
        serializer = InteractionHistorySerializer(InteractionHistory, many=True)
        return Response(serializer.data)
@api_view(['GET'])
def ReadingState_list(request):
        InteractionHistory = ReadingState.objects.all()
        serializer = ReadingStateSerializer(InteractionHistory, many=True)
        return Response(serializer.data)

@api_view(['GET', 'POST'])
def submission_list(request):
    if request.method == 'GET':
        submissions = Submission.objects.all()
        serializer = SubmissionSerializer(submissions, many=True)
        return Response(serializer.data)
    elif request.method == 'POST':
        serializer = SubmissionSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
" adminhome.html "<!-- adminhome.html -->

{% block content %}
<style media="screen">
    body {
        font-family: 'Poppins', sans-serif;
        background-color: #f4f4f4;
        color: #333;
        margin: 0;
        padding: 0;
    }

    h2 {
        color: #23a2f6;
    }

    #dashboard {
        display: flex;
        justify-content: space-around;
    }

    section {
        flex: 1;
        margin: 20px;
        padding: 20px;
        background-color: #fff;
        border: 1px solid #ddd;
        border-radius: 8px;
        transition: transform 0.3s ease-in-out;
        box-sizing: border-box;
    }

   

    button {
        background-color: #23a2f6;
        color: #fff;
        padding: 10px 15px;
        border: none;
        border-radius: 5px;
        cursor: pointer;
    }

    ul {
        list-style-type: none;
        padding: 0;
    }

    li {
        margin-bottom: 10px;
    }

    label {
        display: block;
        margin-bottom: 5px;
        font-weight: bold;
    }

    select,
    button {
        padding: 10px;
        margin-top: 5px;
        margin-bottom: 10px;
    }

    #manage-roles,
    #delete-users {
        margin-top: 40px;
    }
</style>
<section id="monitor-activity">
    <h2>Monitor Platform Activity</h2>

    <button id="toggle-activity">Toggle Activity History</button>
    <div id="activity-history" style="display: none;">
        <h3>Login/Logout Activity</h3>
        <ul>
            <!-- Login/Logout Activity for Admins -->
            <ul>
                {% for InteractionHistory in InteractionHistory_history_admin %}
                    <li>{{ InteractionHistory.student.username }} {{ InteractionHistory.InteractionHistory_type }} at {{ InteractionHistory.InteractionHistory_date|date:"F d, Y H:i:s" }}</li>
                {% endfor %}
            </ul>

            <!-- Login/Logout Activity for Students -->
            <li><strong>Students:</strong></li>
            <ul>
                {% for InteractionHistory in InteractionHistory_history_students %}
                    <li>{{ InteractionHistory.student.username }} {{ InteractionHistory.InteractionHistory_type }} at {{ InteractionHistory.InteractionHistory_date|date:"F d, Y H:i:s" }}</li>
                {% endfor %}
            </ul>

            <!-- Login/Logout Activity for Tutors -->
            <li><strong>Tutors:</strong></li>
            <ul>
                {% for InteractionHistory in InteractionHistory_history_tutors %}
                    <li>{{ InteractionHistory.student.username }} {{ InteractionHistory.InteractionHistory_type }} at {{ InteractionHistory.InteractionHistory_date|date:"F d, Y H:i:s" }}</li>
                {% endfor %}
            </ul>
        </ul>

        <h3>Course Activity</h3>
        <ul>
            <!-- Course Creation Activity -->
            {% for course in courses %}
                <li>Course created: {{ course.name }} by {{ course.created_by.username }} at {{ course.creation_time|date:"F d, Y H:i:s" }}</li>
            {% endfor %}
        </ul>


    </div>
</section>

</div>

{% block manage-accounts %}
<section id="manage-accounts">
    <h2>Manage User Accounts</h2>
<section>
        <h1>Manage User Roles</h1>
        <form method="post" action="{% url 'change_user_role' %}">
            
            {% csrf_token %}
            <label for="user-select">Select User:</label>
            <select name="user_id" id="user-select">
                {% for user in users %}
                    <option value="{{ user.id }}">{{ user.username }}</option>
                {% endfor %}
            </select>
            <label for="role-select">Select Role:</label>
            <select name="role">
                <option value="student">Student</option>
                <option value="tutor">Tutor</option>
                <!-- Add more roles if needed -->
            </select>

            <button type="submit">Change Role</button>
        </form>
    </section>
    <section id="delete-users">
        <h1>Delete User Accounts</h1>
        <ul>
            {% for user in users %}
                <li>
                    {{ user.username }} ({{ user.userprofile.role }})
                    <form method="post" action="{% url 'delete_user' user.id %}" onsubmit="return confirm('Are you sure you want to delete this user?');">
                        {% csrf_token %}
                        <button type="submit">Delete</button>
                    </form>
                </li>
            {% endfor %}
        </ul>
    </section>
    
{% block manage-courses %}
<section id="manage-courses">
    <h2>Manage Courses</h2>

    <ul>
        {% for course in courses %}
            <li>
                {{ course.name }}

                <!-- Modify Course Form -->
                <form method="post" action="{% url 'modify_course' course.id %}">
                    {% csrf_token %}
                    <label for="new_course_name">New Course Name:</label>
                    <input type="text" name="new_course_name" required>
                    <button type="submit">Modify</button>
                </form>

                <!-- Delete Course Form -->
                <form method="post" action="{% url 'delete_course' course.id %}" onsubmit="return confirm('Are you sure you want to delete this course?');">
                    {% csrf_token %}
                    <button type="submit">Delete</button>
                </form>

            </li>
        {% endfor %}
        
    </ul>
</section>
{{ InteractionHistory.InteractionHistory_date|date:"F d, Y H:i:s" }}

{% endblock %}

<form action="{% url 'logout' %}" method="post">
    {% csrf_token %}
    <button type="submit">Logout</button>
</form>
    {% endblock %}
    
      <script>
        document.getElementById('toggle-activity').addEventListener('click', function() {
            var historySection = document.getElementById('activity-history');
            historySection.style.display = (historySection.style.display === 'none' || historySection.style.display === '') ? 'block' : 'none';
        });
    </script>
{% endblock %}
" here are my models.py don't change anything about them "from django.db import models
from django.contrib.auth.models import User
from django.utils.text import slugify  # Import slugify
from django.urls import reverse

class UserProfile(models.Model):
    USER_ROLES = (
        ('student', 'Student'),
        ('tutor', 'Tutor'),
        ('administrator', 'Administrator'),
    )

    user = models.OneToOneField(User, on_delete=models.CASCADE)
    role = models.CharField(max_length=20, choices=USER_ROLES)
    last_login = models.DateTimeField(null=True, blank=True)
    last_logout = models.DateTimeField(null=True, blank=True)
    
class Course(models.Model):
    name = models.CharField(max_length=255)
    students = models.ManyToManyField(User, related_name='courses', blank=True)
    tutor = models.ForeignKey(User, on_delete=models.CASCADE, related_name='tutor_courses')
    created_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
    creation_time = models.DateTimeField(null=True, blank=True)
    def __str__(self):
        return self.name

class CourseMaterial(models.Model):
    title = models.CharField(max_length=255)
    file = models.FileField(upload_to='course_materials/')
    course = models.ForeignKey(Course, on_delete=models.CASCADE)

    def __str__(self):
        return self.title
class Test(models.Model):
    title = models.CharField(max_length=255)
    content = models.TextField()
    file = models.FileField(upload_to='tests/')
    course = models.ForeignKey(Course, on_delete=models.CASCADE)
    upload_date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title
class Chapter(models.Model):
    chapter_name = models.CharField(max_length=20)
    chapter_created_date = models.DateTimeField(auto_now_add=True)
    course = models.ForeignKey(Course, on_delete=models.CASCADE, default=1)
    slug = models.SlugField(unique=True)

    def __str__(self):
        return self.chapter_name

class Assignment(models.Model):
    title = models.CharField(max_length=255)
    description = models.TextField()
    due_date = models.DateField()
    course = models.ForeignKey(Course, on_delete=models.CASCADE)
    student = models.ForeignKey(User, on_delete=models.CASCADE, null=False)
    status = models.CharField(max_length=20, choices=[('pending', 'Pending'), ('completed', 'Completed')])
    grade = models.FloatField(null=True, blank=True)
    feedback = models.TextField(null=True, blank=True)

    def is_user_enrolled(self, user):
        return Enrollment.objects.filter(student=user, course=self.course).exists()
    def __str__(self):
        return self.title

class Grade(models.Model):
    value = models.FloatField()
    course = models.ForeignKey(Course, on_delete=models.CASCADE)
    student = models.ForeignKey(User, on_delete=models.CASCADE, related_name='grades')

    def __str__(self):
        return f"{self.student.username}'s grade in {self.course.name}: {self.value}"


class Attendance(models.Model):
    date = models.DateField()
    course = models.ForeignKey(Course, on_delete=models.CASCADE)
    students_present = models.ManyToManyField(User, related_name='attendances', blank=True)

class Enrollment(models.Model):
    student = models.ForeignKey(User, on_delete=models.CASCADE)
    course = models.ForeignKey('Course', on_delete=models.CASCADE)
    enrollment_date = models.DateField()

    def __str__(self):
        return f"{self.student.username} enrolled in {self.course.name}"

class Material(models.Model):
    title = models.CharField(max_length=255)
    content = models.TextField()
    course = models.ForeignKey('Course', on_delete=models.CASCADE)
    upload_date = models.DateField()
    document_type = models.CharField(max_length=50)  # Assuming you want a text field for document type

    def __str__(self):
        return self.title

class Submission(models.Model):
    student = models.ForeignKey(User, on_delete=models.CASCADE)
    assignment = models.ForeignKey('Assignment', on_delete=models.CASCADE)
    submission_content = models.FileField(upload_to='submission_files/')  # Assuming there's also text content
    submission_date = models.DateField()

    def __str__(self):
        return f"Submission by {self.student.username} for {self.assignment.title}"
class InteractionHistory(models.Model):
    student = models.ForeignKey(User, on_delete=models.CASCADE)
    material_id = models.ForeignKey(Material, on_delete=models.SET_NULL, null=True, blank=True)
    InteractionHistory_type = models.CharField(max_length=50)  # Assuming you want a text field for InteractionHistory type
    InteractionHistory_date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f'{self.student.username} - {self.InteractionHistory_type} at {self.InteractionHistory_date}'

class ReadingState(models.Model):
    student = models.ForeignKey(User, on_delete=models.CASCADE)
    material = models.ForeignKey('Material', on_delete=models.CASCADE)
    read_state = models.FloatField()  # Assuming you want a float field for percentage completed
    last_read_date = models.DateField()

    def __str__(self):
        return f"Reading state of {self.student.username} for {self.material.title}: {self.read_state}% completed on {self.last_read_date}"