Answer the question
In order to leave comments, you need to log in
Why does Django throw TypeError: Abstract models cannot be instantiated?
I have a django 4.0.1 project in which I use the mondodb database. To connect with the database, I use the "djOngo" engine. The database connection is working correctly.
In my project, I need to create models nested in other models in models.py I turned to the official documentation of the "djOngo" engine and tried to implement an example that potentially closes my need, here it is:
from djongo import models
class Blog(models.Model):
name = models.CharField(max_length=100)
tagline = models.TextField()
class Meta:
abstract = True
class MetaData(models.Model):
pub_date = models.DateField()
mod_date = models.DateField()
n_pingbacks = models.IntegerField()
rating = models.IntegerField()
class Meta:
abstract = True
class Author(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField()
class Meta:
abstract = True
def __str__(self):
return self.name
class Entry(models.Model):
blog = models.ArrayField(
model_container=Blog,
)
meta_data = models.ArrayField(
model_container=MetaData,
)
headline = models.CharField(max_length=255)
body_text = models.TextField()
authors = models.ArrayField(
model_container=Author,
)
n_comments = models.IntegerField()
def __str__(self):
return self.headline
class Meta:
verbose_name = 'Entry'
verbose_name_plural = 'Entry'
from django.contrib import admin
from .models import Entry
admin.site.register(Entry)
TypeError: Abstract models cannot be instantiated.
Answer the question
In order to leave comments, you need to log in
Well, everything is written in the text of the error - you cannot call an instance of the abstract model. And the author is precisely that abstract.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question