Skip to content
Advertisement

Tag: django-models

Unsupported lookup ‘category’ for CharField or join on the field not permitted

models.py: This is my views.py file. I show error at: bestseller = Product.objects.filter(product__category__icontains=’BestSeller’) views.py: I want to Bestseller category product at index.html I use Django 4 and pyhton 3.9 Answer You can’t use CharField as a ForeignKey. It should be like this: Or like this (the same logic): This will output all Products in category with name BestSeller.

Django join tables with ForeignKey

I’m trying to join 3 tables with ForeignKey but it returns Null values. I’m using select related and also I tried Insight.objects.all() but both are not working. Here are my models: My View: Answer I solved my problem by the below, I could update the DB with the result of the below query

serializer not being called AttributeError: ‘str’ object has no attribute ‘_meta’

I modified the Auth User by using AbstractUser Class. Registered it in settings. Everything else is working I can create an instance using the User Model BUT The Problem comes during the serialization. My serializer doesn’t throw any error, but any time I try and use the serializer.data I get AttributeError: ‘str’ object has no attribute ‘_meta’. User Model Custom

Django query for column value search?

What is the Django query for this? DB data – I only need record that contain “1.2.3” values not like – (“Cat 1.2.3” or “1.2.3-XY2” or any such value). And pattern “1.2.3” can be anywhere in column where column value can have comma separated values too. Desired Result – When i am performing below Django query – Getting all record

Advertisement