Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django annotate concat string

from django.db.models.functions import Concat
from django.db.models import Value, CharField

class OrderManager(models.Manager):
  def get_queryset(self):
      """Overrides the models.Manager method
         creates another callable field in orders model named 'link'
      """
      qs = super(OrderManager, self).get_queryset()
      .annotate(
        link=Concat(Value("<a href='#'>"), 'order_id', Value('</a>'), output_field=CharField()))
      return qs

class Order(models.Model):
    order_id = models.IntegerField(primary_key=True, null=False)
    # other fields  here 
    objects = OrderManager()
 
Comment

PREVIOUS NEXT
Code Example
Python :: the day before today python datetime 
Python :: pygame center text in rect 
Python :: python read tab delimited file 
Python :: djangodebug toolbar not showing 
Python :: python make directory if not exists 
Python :: python series sort 
Python :: pie chart python pandas 
Python :: print on two digit python format 
Python :: reverse list python 
Python :: python bisection method 
Python :: how to replace null values in pandas 
Python :: kmeans sklearn 
Python :: python show image cv2 
Python :: remainder identifying python 
Python :: changing instance through dict changes all instances 
Python :: talos get best model 
Python :: subplot adjust python 
Python :: python requests pass auth token 
Python :: pandas groupby sum 
Python :: python get words between two words 
Python :: ignore module import log in python 
Python :: pandas et numeric columns 
Python :: sort list of files by name python 
Python :: how to change the favicon in flask 
Python :: rename file python 
Python :: masking function pyspark 
Python :: convert a pandas column to int 
Python :: image from wikipedia module in python 
Python :: add day in date python 
Python :: rock paper scissors game in python 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =