自定义Django Admin面板,我raw_id_fields用来从具有数千个元素的Model中选择一个ForeignKey,因为默认的select-box下拉列表对于这么多元素来说是不方便的.
它可以工作,但它显示了在此图像上可以看到的ID:

有没有办法显示名称或其他字段而不是ID?或者,有没有比使用更好的方法来实现这一目标raw_id_fields?
这是我的代码models.py:
class Structure(MPTTModel):
name = models.CharField(max_length=200, unique=True, verbose_name = _('name'))
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', verbose_name = _('parent'))
def __unicode__(self):
return u"%s" % (self.name)
Run Code Online (Sandbox Code Playgroud)
在admin.py:
class StructureAdmin(tree_editor.TreeEditor):
search_fields = ('name',)
raw_id_fields = ('parent',)
Run Code Online (Sandbox Code Playgroud) 我正在使用启动相机的按钮来执行ios应用程序.
如果设备有可用的相机,我想启用/禁用按钮.
我想检测设备是否有摄像头,以及设备是否有摄像头但是受限制(使用此设备),因此您无法使用它.
我该如何检测这两个选项?
谢谢
我想使用AVCaptureSession使用相机拍摄图像.
它工作正常,我启动相机,我可以得到输出.但是,当我旋转设备时,我在视频方向上遇到了一些问题.
首先,我想支持横向左右方向,也可能是后期的纵向模式.
我执行:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation{
return UIInterfaceOrientationIsLandscapse(interfaceOrientation);
}
Run Code Online (Sandbox Code Playgroud)
当我旋转设备时,它会将应用程序从横向左侧旋转到横向右侧,反之亦然,但是当我在横向左侧时,我只能正确地看到相机.当应用程序处于横向右侧时,视频将旋转180度.
非常感谢你.
更新:
我已经尝试过Spectravideo328的答案,但是当我尝试旋转设备和应用程序崩溃时出现错误.这是错误:
[AVCaptureVideoPreviewLayer connection]: unrecognized selector sent to instance 0xf678210
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AVCaptureVideoPreviewLayer connection]: unrecognized selector sent to instance 0xf678210'
Run Code Online (Sandbox Code Playgroud)
此行中发生错误:
AVCaptureConnection *previewLayerConnection=self.previewLayer.connection;
Run Code Online (Sandbox Code Playgroud)
我把它放在了shouldAutorotateToInterfaceOrientation方法里面.你知道这个错误的原因是什么吗?
谢谢
在Django项目中,我有一个使用MPTT的层次模型,在models.py中定义如下:
class Structure(MPTTModel):
name = models.CharField(max_length=200, unique=True)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
[...]
Run Code Online (Sandbox Code Playgroud)
我正在使用FeinCMS在管理页面中显示此分层数据.我在admin.py中这样做:
class StructureAdmin(tree_editor.TreeEditor):
search_fields = ('name',)
[...]
admin.site.register(Structure, StructureAdmin)
Run Code Online (Sandbox Code Playgroud)
在管理模型页面中,它完美地工作,可以看到层次结构:

它在编辑或添加时也有效:

我在models.py中有另一个模型:
class Track(models.Model):
initialStructure = models.ForeignKey(Structure , related_name='track_initialStructure')
finalStructure = models.ForeignKey(Structure, related_name='track_finalStructure')
[...]
Run Code Online (Sandbox Code Playgroud)
但是,在添加此类新元素时,无法看到层次结构:

我曾尝试使用tree_editor.TreeEditor作为Track的管理视图,但它会产生很多错误,因为Track不是分层的,但是它的一些ForeignKey是.在编辑模型轨道的元素时,如何显示层次结构?
非常感谢你.
我想触发当你从外部html按钮选择项目图例时触发的同一事件.可能吗?
我创建了一个jsfiddle来展示它:http://jsfiddle.net/YcJF8/1/ .
$('#container').highcharts({
chart : {
type : 'spline',
},
xAxis : {
categories : ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series : [{
data : [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
}],
plotOptions : {
series : {
cursor : 'pointer',
}
},
});
$('#button').click(function() {
alert("Fire legenditemclick event");
});
Run Code Online (Sandbox Code Playgroud)
在这个jsfiddle,我有一个按钮,我希望当我点击按钮时,它会触发一个事件或图表检测到的东西,并且单击了项目图例(系列1).
非常感谢你
我有一个在uiwebview组件中加载web的应用程序.我需要在uiwebview和web加载之间进行通信,反之亦然.
我的应用程序在早期的ios中运行正常(例如ios 7.x,6.x和5.x),但现在我已经尝试使用ios 8并且它不起作用.我可以将目标c的信息发送到javascript(使用stringByEvaluatingJavaScriptFromString :),但我无法从javascript接收信息.
为此,我使用了与此处相同的内容:ios将值传递给本机应用程序.我的意思是,我实施:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"URL: %@", [request URL]);
NSURL *URL = [request URL];
if ([[URL scheme] isEqualToString:@"newprotocol"]) {
// something
return NO;
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
当我发送:newprotocol:// xxxxx我总是收到:空白
我知道在ios 8中UIWebView发生了变化,但我想保持与早期版本的兼容性.你知道在ios 8中是否可以这样做吗?做这个的最好方式是什么?
非常感谢你!
我正在使用stagewebview> Flash Builder 4.6
我有一个stagewebview,我加载了一个网址.我想有时在stagewebview上显示一个幻灯片.我尝试过,但面板总是落后于stagewebview.我知道stagewebview不是一个显示对象,但有谁知道我有什么方法可以做到吗?
提前致谢
camera ×2
django ×2
objective-c ×2
django-admin ×1
django-mptt ×1
events ×1
feincms ×1
highcharts ×1
ios ×1
ios8 ×1
iphone ×1
javascript ×1
legend ×1
linechart ×1
panel ×1
python ×1
restrictions ×1
rotation ×1
stagewebview ×1
uiwebview ×1