在Django中返回带有查询集的行号

时间:2019-12-24 01:38:32

标签: django mongodb djongo

我正在使用Django,而正在使用Django的MongoDb。如何返回其中包含行号的查询集?我曾尝试探索mongo的聚合功能,但无法达到结果。

class BubbleTextView : TextView {

    private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
    private val rectPath = Path()
    private val trianglePath = Path()

    private val rectF = RectF()
    private val triangleSize = resources.getDimensionPixelSize(R.dimen.triangle_size_20dp).toFloat()
    private val cornerRadius = resources.getDimensionPixelSize(R.dimen.corner_radius_4dp).toFloat()

    constructor(context: Context?):super(context)
    constructor(context: Context?, attrs: AttributeSet?):super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int):super(context, attrs, defStyleAttr)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)

    init{
        paint.style = Paint.Style.FILL
        paint.color = Color.CYAN
    }

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
        val myWidth = (right - left).toFloat()
        val myHeight = (bottom - top).toFloat()
        val centerX = myWidth / 2f
        val lowerEdgeY = myHeight * 0.8f

        rectF.set(0f, 0f, myWidth, lowerEdgeY)
        rectPath.addRoundRect(rectF,cornerRadius, cornerRadius, Path.Direction.CW )

        val delta = triangleSize * 0.5f
        trianglePath.moveTo(centerX - delta, lowerEdgeY)
        trianglePath.lineTo(centerX + delta, lowerEdgeY)
        trianglePath.lineTo(centerX, myHeight)
        trianglePath.close()
    }

    override fun onDraw(canvas: Canvas?) {
        canvas?.drawPath(rectPath, paint)
        canvas?.drawPath(trianglePath, paint)
        super.onDraw(canvas)
    }
}

预期产量

import uuid
from django import models


class Snippet(models.Model):
    id = models.UUIDField(
        primary_key=True,
        default=uuid.uuid4,
        editable=False,
    )
    title = models.CharField(
        max_length=100,
    )
    body = models.TextField()

0 个答案:

没有答案