'Check if the Attendance Record is Unique'

def validate_duplication(self):

    attendance_records = None
    if self.course_schedule:
        attendance_records = frappe.db.sql(u"select    name    from    `tabStudent    Attendance`    where     DCTB  DCTB  DCTB  DCTB student=    %s    and    ifnull(course_schedule,    '')=    %s    and    name    !=    %s", (self.student, cstr(self.course_schedule), self.name))
    else:
        attendance_records = frappe.db.sql(u"select    name    from    `tabStudent    Attendance`    where     DCTB  DCTB  DCTB  DCTB student=    %s    and    student_group=    %s    and    date=    %s    and    name    !=    %s    and     DCTB  DCTB  DCTB  DCTB (course_schedule    is    Null    or    course_schedule='')", (self.student, self.student_group, self.date, self.name))
    if attendance_records:
        frappe.throw(_(u'Attendance    Record    {0}    exists    against    Student    {1}').format(attendance_records[0][0], self.student))
