georgemarshall / django-cryptography

Easily encrypt data in Django
https://django-cryptography.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
371 stars 70 forks source link

Q Query #20

Closed Bastilla123 closed 4 years ago

Bastilla123 commented 5 years ago

I have following model:

class Adressen(models.Model): geburtsdatum = encrypt(models.DateField(default=None,blank=True,null=True))

views: start = date.today() end = start + timedelta(days=14) Geburtstage = Adressen.objects.filter( Q(geburtsdatummonth=start.month) & Q(geburtsdatumdaygte=start.day) | Q(geburtsdatummonth=end.month) & Q(geburtsdatumdaylte=end.day) ).order_by('geburtsdatum')

Exception:

django.core.exceptions.FieldError: Unsupported lookup 'month' for EncryptedDateField or join on the field not permitted, perhaps you meant month?

thismatters commented 4 years ago

Encrypted fields generally don't support lookup within querysets since the data in the actual table cannot be compared to what it is required to match. The only way to do what you are trying to do would be to query for all of the Adressen objects and iterate over them until you find the one whose attributes match.