我正在尝试在我的表单中自动填充纬度和经度字段我正在以这种方式做这件事
#forms.py
class registerForm(forms.ModelForm):
class Meta:
model=register
fields = ('Availability', 'Status')#'latitude','longitude',
def save(self,ip_address, *args, **kwargs):
g = GeoIP()
lat, lon = g.lat_lon(ip_address)
user_location = super(registerForm, self).save(commit=False)
user_location.latitude = lat
user_location.longitude = lon
user_location.save(*args, **kwargs)
我的观点有这个东西
#views.py
def status_set(request):
if request.method == "POST":
ip_address=request.META['REMOTE_ADDR']
rform = registerForm(data = request.POST)
if rform.is_valid():
register = rform.save(commit=False)
register.user=request.user
register.save(ip_address)
return render_to_response('home.html')
else:
rform = registerForm()
return render_to_response('status_set.html',{'rform':rform})
但是当我尝试提交表单时,它说“save() 至少需要 2 个非关键字参数(给定 1 个)”错误就在这里“ register = rform.save(commit=False)"
我无法弄清楚任何帮助将不胜感激使用 django 1.1。 1 和 GeoIP