Django creando campos calculados en el modelo
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()
Trained Tuna