<s>[INST] Code Review Request - Django Class-Based View (Non-Atomic Data Management)
======================================================================

### Overview
I have created a Django class-based view that handles the creation of students and their respective attendance records in a school management system. However, this code lacks atomic data management, which means that in case of an error during the creation process, it may leave the database in an inconsistent state.

### Code
```python
from django.shortcuts import redirect
from django.views.generic import CreateView
from .models import Student, AttendanceRecord

class StudentCreateView(CreateView):
    model = Student
    fields = ('name', 'dob', 'grade')
    template_name = 'students/student_create.html'
    success_url = '/students/'

    def form_valid(self, form):
        student = form.save()
        attendance_record = AttendanceRecord.objects.create(student=student)
        return redirect(self.success_url)
```
### Question
How can I modify this code to use atomic data management to ensure that if an error occurs during the creation process, the database remains in a consistent state?[/INST]