Extract a queryset which is not in another table using Django orm

나의 재물운? 연애운은?

AI가 봐주는 내 사주팔자 - 운세박사

https://aifortunedoctor.com/

Extract a queryset which is not in another table using Django orm

영리치 0 851 2023.01.30 10:48

990564053_hHjTuYoR_492fd7e8fb0e83f58a36c4be20e6ec09b38e0fa9.png


digitalNodes = DigitalNode.objects.all()
nodeAnswers = NodeAnswer.objects.values_list('node_id', flat=True).filter(user_id = user.id)
oneDigitalNode = digitalNodes.exclude(node_id__in=nodeAnswers).first()



To extract a queryset which is not in another table using Django ORM, you can use the exclude() method on the queryset. Here's an example:


# models.py class MainModel(models.Model): name = models.CharField(max_length=100) class OtherModel(models.Model): main_model = models.ForeignKey(MainModel, on_delete=models.CASCADE) # views.py main_models = MainModel.objects.all() other_models = OtherModel.objects.values_list('main_model', flat=True) excluded_main_models = main_models.exclude(id__in=other_models)


The exclude() method returns a queryset of all MainModel objects whose id is not in the list of main_model values from OtherModel.



와 Django ORM 중인데 백엔드 만만하게 봤었는데 개어려웠는데 한 2시간 넘게 고민한 거 Chat GPT로 5분만에 품 ㅋㅋㅋㅋㅋ 와 질문을 개떡같이 했는데 이걸 잘 알아듣고 답을 주네 ㅋㅋㅋㅋ





Comments

나의 재물운? 연애운은?

AI가 봐주는 내 사주팔자 - 운세박사

https://aifortunedoctor.com/

Category
실시간 인기글
난 아버지처럼 되지 않을래요
영리치
등록된 글이 없습니다.
Magazine
훈남/훈녀
 
 
 
상점
Facebook Twitter GooglePlus KakaoStory NaverBand