问题
my models:
class Mod(models.model)
name = models.CharField(max_length = 255)
co_x = models.DecimalField(max_digits = 11, decimal_places = 8)
co_y = models.DecimalField(max_digits = 11, decimal_places = 8)
my views:
def closedPoint(request):
location_name = str(request.POST.get("lo", default=""))
nokta_x = int(float(request.POST.get("x"))
nokta_y = int(float(request.POST.get("y"))
poi = Point(nokta_x, nokta_y, srid = 900913)
sk = Mod()
poi_s = Point(sk.co_x, co_y, srid = 900913)
resut_poi = Mod.objects.filter(poi_s__distance_lte = (poi, D(km = 7))).filter(name__in = location_name)
here i want to deduct closest point in 7 km but it gives "Invalid parameters given for Point initialization
回答1:
Ok, so it's now clear your error message comes from initializing a Point
class with None
.
That is your first critical problem.
Judging by the error message, my guess is that poi_s
is initialized with None, None
as Mod()
is an unsaved instance with no values and those are the invalid parameters.
sk = Mod() # unsaved Mod instance with no defaults
poi_s = Point(sk.co_x, co_y, srid = 900913)
# sk.co_x is None
Your second problem that will appear after fixing the above is querying a model with an invalid lookup type (specific to PointField
, __distance
) which accepts a tuple. How to solve that, I don't know.
You would have to look at how GeoDjango translates that tuple into a DB lookup.
来源:https://stackoverflow.com/questions/5327684/django-point-definition