这是一个简单的模型:
class TakingCourse(models.Model):
course = models.ForeignKey(Course)
term = models.ForeignKey(Term)
Run Code Online (Sandbox Code Playgroud)
取而代之的Django的创建默认主键,我想同时使用course,并term作为主键-结合在一起,他们唯一标识一个元组.这是Django允许的吗?
在相关的说明:我试图代表用户以某些方式参加课程.有一个更好的方法吗?
class Course(models.Model):
name = models.CharField(max_length=200)
requiredFor = models.ManyToManyField(RequirementSubSet, blank=True)
offeringSchool = models.ForeignKey(School)
def __unicode__(self):
return "%s at %s" % (self.name, self.offeringSchool)
class MyUser(models.Model):
user = models.ForeignKey(User, unique=True)
takingReqSets = models.ManyToManyField(RequirementSet, blank=True)
takingTerms = models.ManyToManyField(Term, blank=True)
takingCourses = models.ManyToManyField(TakingCourse, blank=True)
school = models.ForeignKey(School)
class TakingCourse(models.Model):
course = models.ForeignKey(Course)
term = models.ForeignKey(Term)
class Term(models.Model):
school = models.ForeignKey(School)
isPrimaryTerm = models.BooleanField()
Run Code Online (Sandbox Code Playgroud) 我正在尝试打印所有会议的清单,并为每个会议打印3个演讲者.
在我的模板中,我有:
{% if conferences %}
<ul>
{% for conference in conferences %}
<li>{{ conference.date }}</li>
{% for speakers in conference.speakers %}
<li>{{ conference.speakers }}</li>
{% endfor %}
{% endfor %}
</ul>
{% else %}
<p>No Conferences</p>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
在我的views.py文件中我有:
from django.shortcuts import render_to_response
from youthconf.conference.models import Conference
def manageconf(request):
conferences = Conference.objects.all().order_by('-date')[:5]
return render_to_response('conference/manageconf.html', {'conferences': conferences})
Run Code Online (Sandbox Code Playgroud)
有一个名为会议的模型.它有一个名为Conferences的类,其中有一个名为扬声器的ManyToManyField
我收到错误:
Caught an exception while rendering: 'ManyRelatedManager' object is not iterable
Run Code Online (Sandbox Code Playgroud)
用这一行: {% for …
我有两张桌子,Proteins和Species.Protein有Species.Id外键约束.当我插入数据时,我知道蛋白质所属物种的名称,但不知道Id.所以我做了以下事情:
PreparedStatement query = connection.prepareStatement(
"SELECT Id FROM Species WHERE ShortName = ?");
query.setString(1, protein.getSpecies().getShortName());
ResultSet result = query.executeQuery();
if (result.next()) {
PreparedStatement statement = connection.prepareStatement(
"INSERT INTO Proteins(SpeciesId, UniProtKBAccessionNumber) VALUES (?, ?)");
statement.setString(1, result.getString(1));
statement.setString(2, protein.getUniProtKBAccessionNumber().toString());
statement.execute();
}
else
throw new IllegalArgumentException("The species of this protein is not recognized!");
Run Code Online (Sandbox Code Playgroud)
基本上,我得到与名称对应的Id,然后插入蛋白质.这在许多方面看起来非常笨拙.是否有更优雅的方式来实现这一目标?我正在研究SQLite数据库.
R:使用Lattice与ggplot2有什么优缺点?
我有一个在Firefox和Chrome中运行良好的页面.然而,IE 8决定在调整浏览器大小时不显示div.大多数页面看起来很好,但我用于内容的div不会,只是在我调整IE大小时消失
<div id="wrapper">
<div id="innerWrapper" style="width:215px;">
<div id="mainColumn" style="height:750px; width:600px; float: left; clear:both; position:absolute;">
<div id="mainContent" style="float:left; ">
content here disappears on resize.
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作条形图用户控件.我正在使用a创建每个栏DataTemplate.
问题是为了计算每个条的高度,我首先需要知道它的容器的高度(TemplatedParent).不幸的是我有:
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource HeightConverter}, Mode=OneWay}"
Run Code Online (Sandbox Code Playgroud)
不起作用.每次将值NaN返回到我的Converter.RelativeSource={RelativeSource TemplatedParent}在这种情况下不起作用?我还能做些什么来让我的DataTemplate与正在应用的元素"对话"?
这里有帮助,这是准系统DataTemplate:
<DataTemplate x:Key="BarGraphTemplate">
<Grid Width="30">
<Rectangle HorizontalAlignment="Center" Stroke="Black" Width="20" Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource HeightConverter}, Mode=OneWay}" VerticalAlignment="Bottom" />
</Grid>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud) 我需要扩展实例的行为,但我无法访问该实例的原始源代码.例如:
/* I don't have the source code for this class, only the runtime instance */
Class AB
{
public void execute();
}
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我会截取每个执行调用,计算一些sutff然后调用原始执行,类似于
/* This is how I would like to modify the method invokation */
SomeType m_OrgExecute;
{
AB a = new AB();
m_OrgExecute = GetByReflection( a.execute );
a.execute = MyExecute;
}
void MyExecute()
{
System.Console.Writeln( "In MyExecute" );
m_OrgExecute();
}
Run Code Online (Sandbox Code Playgroud)
那可能吗?
有没有人有这个问题的解决方案?
我正在JUnit中编写一些集成测试.这里发生的是当我连续一起运行所有测试(而不是单独)时,数据库中持久存储的数据总是会发生变化,测试会在执行期间发现意外数据(由前一个测试插入).
我正在考虑使用DbUnit,但我想知道它是否重置每次执行之间的自动增量索引(因为测试还会检查持久化实体的ID).
谢谢
M.
简短版本:如何摆脱多版本的噩梦?
长版本:多年来,我已经使用了几个版本的python,更糟糕的是,python的几个扩展(例如pygame,pylab,wxPython ......).每次它在不同的设置上,使用不同的操作系统,有时候是不同的架构(比如我的旧PowerPC mac).
现在我正在使用mac(x86-64上的OSX 10.6),每次我想恢复比几个月更早的脚本时,这是一个依赖性的噩梦.Python本身已经有三种不同的版本/usr/bin(2.5,2.6,3.1),但我必须从macports安装2.4 for pygame,其他东西(不记得是什么)迫使我从macports安装所有其他三个,所以在在我的系统上,我是七个(!)python实例的幸福拥有者.
但这不是问题,问题是,它们都没有安装正确的(即同一组)库,其中一些是32位,大约64位,现在我几乎丢失了.
例如,我现在正在尝试运行一个三年前的脚本(不是由我编写的),它曾经使用matplotlib/numpy在wxwidgets窗口的矩形内绘制实时图.但我惨遭失败:来自macports的py26-wxpython将无法安装,库存python包含wxwidgets但在32位和64位之间也存在一些冲突,并且它没有numpy ......真是一团糟!
显然,我做错了事.如何你 usally与所有的混乱应对?
据我所知,visual studio是一个GUI代码生成器,除了其他东西,你拖动一个按钮并把它放在窗口上,在场景后面为你编写代码.
我的问题是:
什么是Visual Studio默认使用的GUI框架??? 我知道它集成了一些GUI工具包,如Fox,GTK和QT.
django ×2
python ×2
.net ×1
binding ×1
c# ×1
css ×1
database ×1
dbunit ×1
dependencies ×1
foreign-keys ×1
ggplot2 ×1
hibernate ×1
html ×1
insert ×1
installation ×1
java ×1
jdbc ×1
lattice ×1
many-to-many ×1
models ×1
orm ×1
plot ×1
r ×1
resize ×1
runtime ×1
select ×1
silverlight ×1
sqlite ×1
wpf ×1