Django在多个多个实例中创建查询集或唯一项列表

时间:2017-12-08 04:38:50

标签: python django

我有QuestionSet这是一个很多问题。每个QuestionSet都有多个questions与之关联。

我想获得两个(或更多)questions

中所有唯一QuestionSets的列表

例如:

First QuestionSet = Questions(1,2,3)
Second QuestionSet = Questions(1,3,4)

Output:
List/Queryset/Something of Questions(1,2,3,4)

models.py

class QuestionSet(models.Model):
    name = models.CharField(max_length=255)
    questions = models.ManyToManyField(Question)


class Question(models.Model):
    question_num = models.IntegerField(default=0,blank=False)

1 个答案:

答案 0 :(得分:1)

也许试试这个:

public class MyWatermark implements
        AssignerWithPeriodicWatermarks<Tuple2<String, MyEvent>> {

    private final long maxTimeLag = 5000;

    @Override
    public long extractTimestamp(Tuple2<String, MyEvent> event, long previousElementTimestamp) {
        try {
            return event.f1.eventTime;
        }
        catch(NullPointerException ex) {}

        return System.currentTimeMillis() - maxTimeLag;
    }

    @Override
    public Watermark getCurrentWatermark() {
        return new Watermark(System.currentTimeMillis() - maxTimeLag);
    }
}

您可以在文档中找到更多内容:Django aggregates