Can't query from django where field name has double underscore.
This is because in the django query language __
has its own meaning
so how can I query a field whose actual name is "my__fyeild__name"
?
template.fields.filter(my__fyeild__name="aaa")
In the database the column has a name with two underscores __
, and I am not allowed to rename that column.
You can't, since Django will always split on the __
part. But I think you do not need this anyway. You can define a field at the Django level, that has a different name on the database level.
We can define a model for example with a field where we specify the name of the column at the database level with the db_column=...
parameter [Django-doc]:
class SomeModel(models.Model):
my_field_name = models.CharField(max_length=128, db_column='my__field__name')
So here you can query on my_field_name
, and Django will automatically use the my__field__name
in the query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With