i have a dict of filters ,
something like
{
"name": "string",
"status": [
"A", "B"
],
"reg": "string",
"oc": [
"As","jb"
]
}
```query_set = query_set.filter(**filters)``` This works fine for all the
filters whose type is not list , How do apply the filters
Simply put - you can't. not without if statements.
What I would do is something like this:
query = Q()
for item in kwargs.items():
if isinstance(item[1], list):
query &= Q(**{f"{item[0]}__in": item[1]})
else:
query &= Q(**{item[0]: item[1]})
query_set = query_set.filter(query)
I understand that -- my question is why the AlterField operation in this
case didn't add a migration dependency.
On Wednesday, May 27, 2020 at 6:44:16 PM UTC-10, Durai pandian wrote:
>
> When you make any changes to the field, AlterField will be added rather
> than AddField.
>
> On Thu, May 28,
Actually I want to filter all users those are matched with currently logged
in users based on location or education details like maybe institute_name
or specialization. Is it possible to search in multiple tables?!
I almost spent 2 days but still I stuck in the position.
Any help would be appreciat
Hi,
I am new to django and going through a tutorial and now confused with one
particular implementation.
models.py
import json
from django.core.serializers import serialize
from django.db import models
from django.conf import settings
# Create your models here.
def upload_update_image(insta
Django users,
There was a discussion in Stack Overflow related to an answer of mine - how
to access settings from templates in Django [
https://stackoverflow.com/a/53953578/1412564]. And I would like to know -
is it generally unsafe to expose all my settings to templates and why?
Should I use the
Yes Andreas Kuhne, I ultimately went with something like this only!!
Thanks for the reply.
On Thursday, May 28, 2020 at 5:37:33 PM UTC+5:30, Andréas Kühne wrote:
>
> Simply put - you can't. not without if statements.
>
> What I would do is something like this:
>
> query = Q()
>
> for item in
Hi Soumen,
You can filter on another table by using __, for example:
User.objects.filter(profile__profiles__institute_name="Example")
Or:
User.objects.filter(profile__profiles__institute_name__in=["Example 1",
"Example 2"])
אורי
u...@speedy.net
On Thu, May 28, 2020 at 11:27 PM Soumen Khatua
Hi Soumen,
Sometimes prefetch_related is much faster and more efficient than
select_related. I usually prefer to use prefetch_related.
Uri.
אורי
u...@speedy.net
On Thu, May 28, 2020 at 12:42 AM Soumen Khatua
wrote:
> Actually I want to fetch all users from User table and users location from
>
The suggested code will not work because, at this point, the "id" has not
yet been generated by the database (unlike the other data which is
typically entered by the user).
You will need to move this code to a post_save signal function -
https://docs.djangoproject.com/en/3.0/ref/signals/#post-s
10 matches
Mail list logo