开发者

adding on elements of a paired record to the original record (perhaps using a subselect?)

My data and model looks more or less like this:

      ID      NAME   STUFF    PAIRED_AGAINST
      1       john    xxx       3
      2       jane    yyy       4
      3       jill    zzz       1
      4       jake    aaa       2

class Swaps(models.Model):
    name = models.CharField()
    stuff = models.CharField()
    paired_against = models.IntegerField()

I need help, I think with a subselect, that will return a queryset that gives me:

id, name, stuff, paired_against, paired_against.name, p开发者_如何学Pythonaired_against.stuff

Many thanks!


Is paired_against the primary key for a different person? Then you should be using a ForeignKey instead of an integer field.

class Swaps(models.Model):
    name = models.CharField()
    stuff = models.CharField()
    paired_against = models.ForeignKey(self, blank=True, null=True)

Edit

Thanks Daniel!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜