— Django, Django admin — 1 min read
and let me tell you I am not the original source for this, a colleague of mine discovered it. I thought it was really cool, so I decided to share it here.
One of the most notable features of Django is its admin panel. Things Django can provide out of the box is just overwelhming at times. For someone like me who doesn't like SQL that much, Django's admin panel is a Godsend 😍.
In the Django admin panel, you can add the fields by which you want to search. But let's say the code is already pushed and you want to filter by a field which is not configured in the admin.py
file. Of course, you can make the changes in the code and push it again just to find out that there is another field required.
Now that we have the backstory, here's the trick: lets says you have a model with a field named foo
and you want to get all the records that contain the word cool
. To get the filtered result, open the model page in the admin panel and in the address bar add the following:
http://127.0.0.1:8000/admin/myapp/mymodel?foo__icontains=cool
Looks familiar? Yes, it's our very own Field Lookups provided by the Django ORM.
For someone who uses the Django admin panel extensively, will appreciate this 😘