ivelum / djangoql

Advanced search language for Django
MIT License
989 stars 88 forks source link

RFE: Lookup two field values #43

Open vkrizan opened 5 years ago

vkrizan commented 5 years ago

(Feature Request)

Hello,

Would it be possible to extend the query language to support lookup by other fields value?

For example:

name ~ title

would translate to

Q(name__icontains=F('title'))

The suggestions can also offer the field name in the context where a value is expected.

Thank you for consideration.

stebunovd commented 5 years ago

hey Viliam,

thank you for the idea, sounds interesting. I wonder if references to other fields alone would feel like a self-sufficient feature. I guess that when we use F() in Django, it would be quite often used as a part of an expression, for example:

Q(date_published__lte=F('date_created') + timedelta(days=1))

If we start thinking about it this way, taking into account complex expressions and functions, the scope of the feature starts to look huge. Of course, this is not always the case, and sometimes F() is used alone. I don't have any stats though.

On one hand, I can understand the need for referencing other fields. On the other hand, I'm afraid that it may be a path down the rabbit hole and may add too much complexity to the library. What do you think?

thanks,

Denis

vkrizan commented 5 years ago

Hello Denis,

Your points are very valid. We had a use-case when two dates have been compared, if one precedes the other. I understand that this might not be a very common case, and would lead to more complex structures, as you mentioned.

Unless anyone would have another use-case, we can close this issue.

violuke commented 4 months ago

We'd love to see this. We were also looking for date related comparison - we have an invoice model and were looking for invoices where the invoice_date is different from the delivery_date :+1: