在我的Django网站中,我正在创建一个与网站中安装的其他应用程序动态交互的类.我必须对每个应用程序的每个字段进行操作.
所以我想在列表中保存所有已安装应用程序的名称,并获取每个应用程序的属性.有一种方法可以使用迭代器或其他东西吗?
我想在管理界面的添加/更改表单中添加自定义按钮.默认情况下,只有三个:
保存并添加另一个
保存并继续编辑
保存
我在我的forms.py文件中创建了一些自定义方法,我想创建按钮来调用这些方法.我使用了片段http://djangosnippets.org/snippets/1842/,但这并不是我想要的.这个允许从admin.py文件创建按钮和调用方法,而不是forms.py.
有没有办法做到这一点?
这是我的admin.py代码:
class CategoryAdmin(admin.ModelAdmin):
prepopulated_fields = { "alias": ("title",) }
form = CategoryForm
admin.site.register(Category, CategoryAdmin)
Run Code Online (Sandbox Code Playgroud)
我的forms.py代码,
class CategoryForm(forms.ModelForm):
"""
My attributes
"""
def custom_method(self):
print("Hello, World!")
Run Code Online (Sandbox Code Playgroud)
如何创建一个调用"custom_method()"的按钮?
我在我的Java项目中使用数据库,我想在其中存储日期,第5和第6个参数是Date Object.我使用下面的解决方案,但我在指示的行中有错误:
PreparedStatement creerFilm = connecteur.getConnexion().prepareStatement(
"INSERT INTO FILM (ID, REF, NOM, DISTRIBUTEUR, DATEDEBUT, DATEFIN) "+
"VALUES (?, ?, ?, ?, ?, ?)");
creerFilm.setInt(1, getId());
creerFilm.setString(2, getReference());
creerFilm.setString(3, getNomFilm());
creerFilm.setString(4, getDistributeur());
// These next two lines
creerFilm.setDate(5, new Date (getDateDebut().getDate()));
creerFilm.setDate(6, new Date (getDateFin().getDate()));
// The above two lines
creerFilm.executeUpdate();
creerFilm.close();
Run Code Online (Sandbox Code Playgroud)
你能帮我解决一下吗?
谢谢
我在我的应用程序中的UIImageView中有一个UIImage.
在纵向模式下,图像居中,但当我切换到横向模式时,它仍然在左侧.
所以我在我的.m文件中添加了以下方法,但问题是我有一个TabBar应用程序,因此当我在另一个选项卡上旋转设备并返回包含图像的选项卡时,它不会自动旋转.
在任何标签上旋转设备时,有一种方法可以自动旋转应用程序的所有元素吗?
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){
background.image = [UIImage imageNamed:@"back2-landscape.png"];
} else if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)){
background.image = [UIImage imageNamed:@"back2-portrait.png"];
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢 :-)