问题列表 - 第26172页

Django模型:使用多个值作为关键?

这是一个简单的模型:

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)

python database django models

1
推荐指数
1
解决办法
2564
查看次数

列出ManyToManyField中的对象

我正在尝试打印所有会议的清单,并为每个会议打印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 …

django many-to-many django-templates

50
推荐指数
2
解决办法
4万
查看次数

插入具有部分来自另一个表的值的记录

我有两张桌子,ProteinsSpecies.ProteinSpecies.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数据库.

sqlite select jdbc foreign-keys insert

0
推荐指数
1
解决办法
2994
查看次数

22
推荐指数
2
解决办法
1万
查看次数

Internet Explorer 8 - Div在调整大小时消失

我有一个在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)

html css internet-explorer resize

3
推荐指数
1
解决办法
5100
查看次数

DataTemplate中的TemplatedParent绑定的Silverlight RelativeSource,是否可能?

我正在尝试制作条形图用户控件.我正在使用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)

silverlight wpf binding relativesource

4
推荐指数
1
解决办法
4607
查看次数

C#在运行时更改类方法

我需要扩展实例的行为,但我无法访问该实例的原始源代码.例如:

/* 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)

那可能吗?

有没有人有这个问题的解决方案?

.net c# runtime

4
推荐指数
1
解决办法
1万
查看次数

集成测试 - Hibernate和DbUnit

我正在JUnit中编写一些集成测试.这里发生的是当我连续一起运行所有测试(而不是单独)时,数据库中持久存储的数据总是会发生变化,测试会在执行期间发现意外数据(由前一个测试插入).

我正在考虑使用DbUnit,但我想知道它是否重置每次执行之间的自动增量索引(因为测试还会检查持久化实体的ID).

谢谢

M.

java orm dbunit integration-testing hibernate

4
推荐指数
1
解决办法
3181
查看次数

如何维护长期存在的python项目依赖项和python版本?

简短版本:如何摆脱多版本的噩梦?

长版本:多年来,我已经使用了几个版本的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与所有的混乱应对?

python installation dependencies multiple-versions

10
推荐指数
2
解决办法
719
查看次数

Visual Studio默认使用的GUI框架是什么?

据我所知,visual studio是一个GUI代码生成器,除了其他东西,你拖动一个按钮并把它放在窗口上,在场景后面为你编写代码.

我的问题是:

什么是Visual Studio默认使用的GUI框架??? 我知道它集成了一些GUI工具包,如Fox,GTK和QT.

user-interface visual-studio

5
推荐指数
2
解决办法
1718
查看次数