Joey Fran
Joey Fran

Reputation: 627

Is it possible generate a hash of result set using django orm?

I need something like this: How to generate a hash of the result set in Postgress?

Is it possible using django orm?

Does anyone have any reference?

Upvotes: 0

Views: 386

Answers (1)

Davit Tovmasyan
Davit Tovmasyan

Reputation: 3588

In the case of Django's User model it will be like below:

from django.contrib.auth.models import User
from django.db.models import Concat, Func, CharField

User.objects.annotate(
    hash=Func(
        Concat('first_name', 'last_name', output_field=CharField()),
        function='md5',
    )
)

Upvotes: 1

Related Questions