我正在尝试列出按用户位置距离排序的地方,我收到空查询错误。我的模型在models.py中被定义为
Sub testing()
Dim cn As Object
Dim rs As Object
Dim sql As String
Dim wb As Workbook
Dim wsEndTarget As Worksheet
Set wb = ThisWorkbook
Set wsEndTarget = wb.Sheets("Sheet3")
Set cn = CreateObject("ADODB.Connection")
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.connectionString = "Data Source=" & _
"C:\Users\xxxxx\Documents\sqlSheet.xlsm" & ";" & _
"Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
.Open
End With
sql = "SELECT * FROM [Sheet2$] WHERE Rating = 'WBS PWT'"
Set rs = CreateObject("ADODB.Recordset")
rs.Source = sql
rs.ActiveConnection = cn
rs.Open sql
wsEndTarget.Activate
For iCols = 0 To rs.Fields.Count - 1
wsEndTarget.Cells(1, iCols + 1).Value = rs.Fields(iCols).Name
Next
wsEndTarget.Range(wsEndTarget.Cells(1, 1), _
wsEndTarget.Cells(1, rs.Fields.Count)).Font.Bold = True
wsEndTarget.Range("A2").CopyFromRecordset rs
wb.Close
rs.Close
cn.Close
Set wb = Nothing
Set wsEndTarget = Nothing
Set cn = Nothing
Set rs = Nothing
End Sub
并在我的views.py中尝试过:
class Place(models.Model):
name = models.CharField(max_length=200)
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text="Unique ID for this particular shop across whole library")
location = gis_models.PointField("longitude/latitude",
geography=True, blank=False, null=True)
#objects = gis_models.GeoManager()
def __unicode__(self):
return self.name, 'location'
class User(AbstractUser):
"""User model."""
username = None
email = models.EmailField(_('email address'), unique=True)
maplocation = gis_models.PointField("longitude/latitude", geography=True, blank=False, null=True)
当我尝试打开我的网页时出现此错误
@login_required
def home(request):
"""
View function for home page.
"""
place_list = Place.objects.all()
user = User.objects.get(email=request.user)
ref_location = user.maplocation
place_ordered = (Place.objects.annotate(distance=D(('location', ref_location)))
.order_by('distance'))
return render(
request,
'home.html',
context={'place_list':place_list, 'place_ordered': place_ordered},
)