'Django annotate a static value to queryset
Is it possible to add an static field value to django query set by annotate or any other way? for example i have an query set called rooms. I want all rooms have a static field in query set not in database. for example:
rooms[0].some_field = "static_value"
Thanks in advance.
Solution 1:[1]
Yes, you can annotate this with Value [Django-doc]:
from django.db.models import CharField, Value
MyModel.objects.annotate(
some_field=Value('static_value', output_field=CharField())
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
