Reputation: 1977
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.
Upvotes: 7
Views: 5232
Reputation: 477749
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())
)
Upvotes: 17