150_下拉菜档实现
1.实现dropbox下拉的功能的顺序
1.1 因为这个不是form表单里面的下拉框
ui_setting!
selection_box
1. form-control 下拉菜单在表单里面的时候有一个'下拉菜单保护机制',默认的是浏览器自带的一个比较丑陋的表单并且是不可以进行修改的,所以需要用延迟加载的方式进行重写!
- 注意传递的数据的形式,用{A:{‘a’:a,’b’:b,’c’:c ,’d’:d}}可以增加
untable_selection_box = {
'province':
{
'北海道 HOKKAIDO': u'北海道 HOKKAIDO',
'青森県 AOMORI': u'青森県 AOMORI',
'岩手県 IWATE':u'岩手県 IWATE',
- button 按键自动的跳转 - - 这个是自己犯傻了
是因为在js 那边有一个写了一个跳转的语句
<script type="text/javascript">
$('#a').click(function(e){
e.preventDefault();
var filtervalue= document.getElementById('filter').value;
var selectvalue_one = document.getElementById('filter-display');
var index_one = selectvalue_one.selectedIndex;
var selectValue_one = selectvalue_one.options[index_one].text;
var selectvalue = document.getElementById('insert_value');
var index = selectvalue.selectedIndex;
var selectValue_s = selectvalue.options[index].text;
console.log(filtervalue+selectValue_s)
var url = '/property/search_province/?a='+selectValue_s+'&b='+filtervalue+'&c='+selectValue_one
//a = province b ='NameUnicode ' c = selectbox_one
url = encodeURI(url);
var link = document.getElementById("a");
link.setAttribute('href',url)
window.location.href=url
})
</script>
5.前端代码,untable_selection_box.province
<div class="col-sm-12" style="padding:0px;0px;0px;-10px;">
<div class="col-sm-2" >
<select id="insert_value" class="form-control" >
{% for Prefectures in untable_selection_box.province %}
<option value='{{ Prefectures }}' id='{{Prefectures}}'>{{Prefectures}}</option>
{% endfor %}
</select>
</div>
</div>
6views的函数,直接从ui_setting 引入,不是作为全局变量的形式引入的,ui_setting
```
from ui_setting import module_sets, ui_sets,untable_selection_box
在view函数里面直接传到前端就行了!!
return render_to_response(ui_sets[‘search_property_view’], {‘untable_selection_box’:untable_selection_box,’properties’: properties, ‘message_for_add_result’:message_for_add_result}, context_instance = RequestContext(request))
## Basic function 要求 ##
英文版:
attribute 类型的实现
Django modal get attribute name
def FindRange(object list ,attribute,request):
if not object or object == []:
max = object list[0].attribute
min = object list[0].attribute
for i in object list:
if not no_access():
return 404
else:
if i.attribute >= max:
max = i.attribute
if i.attribute <= min :
min = i.attribute
output.min = min
output.max = max
return output
Add a basic function:
parameter: object (which indicates an object elements list, ex. Property List, Availability List, ), attribute (which indicates an specific object attributes, ex. Rent_Warehouse), request
functional: 1. no_access cleansing to exclude any element that is not accessible 2. get the largest and smallest values for the parameter attribute in object list. 3. return the values
output: an return object named ‘output’, which has output.max, output.min
use basic function above in availability search view to get the min/max rent/area of availability list which would be sent to front-end.
Use the value in front-end to achieve dynamic-display of filter range.
1. 设计一个自定义的对象,使用的是class ! 我理解的错误是把class 设计在函数外面 变成了全局变量了! 这个output 类型的对象是需要设计出来的!
class output:
def init(self,max_range,min_range):
self.max_range = No module named loadingmax_range
self.min_range = min_range
2. 获取Django model 中字段的string 类型的名称get_modal函数
[获取Django model中的字段名称和字段的类型](http://www.loonapp.com/blog/12/)
作用是获得数据库里面已经有的
verbose_name 是和field.name 相互对应的,这个
modelobj = apps.get_model(‘horizonforgov’,’Availability’)
for field in modelobj._meta.fields:
fielddic[field.name] = field.name
#返回的是‘charfield’,’textfield’,等这些类型
2.1 No module named loading问题!无法得到get_model 这个函数,我觉得还是有点问题的,为什么没有办法引入呢
try:
from django.db.models.loading import get_model
except ImportError:
from django.apps import app
为了有更加通用的功能,这边判断是什么样的对象,Property还是availablity 对象
if isinstance(objectlist[0],Property):
type_object = ‘Property’
elif isinstance(objectlist[0],Availability):
type_object = ‘Availability’
这边还是没有办法明白为什么要引入get_model 函数?
modelobj = apps.get_model(‘horizonforgov’,type_object)
for field in modelobj._meta.fields:
fielddic[field.name] = field.name #返回的是‘charfield’,’textfield’,等这些类型
attr = fielddic[attribute]
利用__getattribute__函数获得对应对象的属性!!
for i in objectlist:
if not can_access(i,request):
render_to_response(‘no_access.html’)
elif i.getattribute(attr) >= max_range:
max_range = i.getattribute(attr)
elif i.getattribute(attr) <= min_range:
min_range = i.getattribute(attr)
5. gitHub改变秘钥的步骤
5.1 确定连接的帐号是谁的
sh -T git@github.com
5.2 创建一个新的密钥
ssh-keygen -t rsa -b 4096 -C “your_email@example.com”
5.3 打开公钥,贴在gitHub上
vim /home/ubuntu/.ssh/id_rsa.pub +Tab
“`