开发者

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

开发者 https://www.devze.com 2023-03-10 14:50 出处:网络
My data and model looks more or less like this: IDNAMESTUFFPAIRED_AGAINST 1johnxxx3 2janeyyy4 3jillzzz1 4jakeaaa2

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

精彩评论

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