0

I need to have a CharField with custom __eq__ function so that when I run model_class.objects.filter(id=something) instead of just checking equality of both strings, my custom __eq__ function should be run. Or is there any other way to implement the same equality check other than creating a custom __eq__ function.

[Edit] My custom __eq__ function involves cutting the string into various sections and evaluating each section differently. My point is, it does not have an equivalent SQL statement.

icyfire
  • 1,170
  • 8
  • 21
  • You are overriding `==`, not `=`. Nitpicking aside, the equality there is converted to an SQL statement, so no, it won't run your custom Python code. If you elaborate what your custom `__eq__` function actually does maybe someone can help. – Selcuk Jun 18 '18 at 04:10
  • The problem is that my custom equality function does not have an equivalent SQL statement. If it had one I could've used custom field lookup functions. – icyfire Jun 18 '18 at 04:16
  • If there's no equivalent SQL, what are you expecting any custom code to do? `filter` runs a query in the database by definition. – Daniel Roseman Jun 18 '18 at 08:20

0 Answers0