vendredi 4 septembre 2020

I am geeting error in unit testing of django app

I am geting error "ValueError: Cannot assign "'12A20'": "Attendance.rollno" must be a "Student" instance." how to solve it ?? Is another way for testing when foreign key is present in Django? model.py

 class Student(models.Model):
     classId=models.ForeignKey(Class,on_delete=models.CASCADE)
     name=models.CharField(max_length=20)
     fatherName=models.CharField(max_length=20)
     motherName=models.CharField(max_length=20)
     address=models.TextField(max_length=100)
     section = models.CharField(max_length=2)
     prevClass=models.IntegerField()
     prevClassMark=models.IntegerField()
     prevResult=models.ImageField(upload_to='images/')
     gender=models.CharField(max_length=6)
     image=models.ImageField(upload_to='images/')
     stream=models.CharField(max_length=10,)#choices=Stream)
     department=models.CharField(max_length=15)
     dob=models.CharField(max_length=12)
     rollno = models.CharField(max_length=10)
     password=models.CharField(max_length=30)

  class Attendance(models.Model):
     rollno=models.ForeignKey(Student,on_delete=models.CASCADE)
     class_id=models.ForeignKey(Class,on_delete=models.CASCADE)
     date=models.CharField(max_length=11)
     status=models.CharField(max_length=7)

tests.py

class AttendanceTest(TestCase):
    def setUp(self):
        Attendance.objects.create(
        rollno='12A20',
        class_id=121,
        date='2020-09-03',
        status='Present'
        )
        Attendance.objects.create(
        rollno='13A20',
        class_id=121,
        date='2020-09-03',
        status='Present'
        )
    def test_Attendance(self):
        qs=Attendance.objects.all()
        self.assertEqual(qs.count(),2)



Aucun commentaire:

Enregistrer un commentaire