Reputation: 91
I am working on a project which has one abstract model and one main model for Djongo. When I try to insert a value, it is getting inserted without errors. But when I try to retrieve the data I get " Abstract models cannot be instantiated".
Here is my model:
class Exam_questions(models.Model):
question=models.CharField(max_length=200,null=True)
options=ArrayField(models.CharField(max_length=50))
answer=models.CharField(max_length=50,null=True)
types=models.CharField(max_length=50,null=True)
class Meta:
abstract=True
class ExamDetails(models.Model):
_id=ObjectIdField()
exam_id=models.IntegerField(null=False,default=0)
questions=models.EmbeddedField(model_container=Exam_questions)
objects = models.DjongoManager()
here is my code for querying:
def exams_questions(request,exam_id):
get_exams=ExamDetails.objects.filter(exam_id=3)
print(get_exams)
return HttpResponse("hello") # have given this response only for testing
When I try to iterate or get values in the variable get_exams I am getting "Abstract models cannot be instantiated" error. Please help!
Thanks
EDIT:
I fixed it . I did pip install djongo
which downgraded the version of django from 3.2 to 3.0.5 which fixed the issue.
Upvotes: 9
Views: 6028
Reputation: 380
it will be by Downgrading your django version to 3.1.12
pip install django==3.1.12
Upvotes: 7
Reputation: 1
Remove the Class Meta: abstract=True From Exam_questions class. And see
Upvotes: -2