AttributeError: 'NoneType' object has no attribute 'distinct'

531 Views Asked by At

I have the below table view

CREATE VIEW vStaff
AS
SELECT ContactInfo .*, Staff.position
FROM ContactInfo 
LEFT JOIN Staff ON Staff.name = ContactInfo.name

that selects information from these two models

class ContactInfo(models.Model):
    name = models.CharField(max_length=30)
    email = models.EmailField(max_length=30)
    address = models.CharField(max_length=30)

class Staff(models.Model):
    name = models.CharField(max_length=30)
    position = models.CharField(max_length=30)  

However, when I try to select from the vStaff like below in modelAdmin I get the above error

Staff.objects.annotate(val=RawSQL("SELECT * FROM vStaff", ()))

AttributeError: 'NoneType' object has no attribute 'distinct'

0

There are 0 best solutions below