Как добавить кнопки + на поля типа "многие ко многим" в TabularInline

Как добавить знак "+" для добавления поля Many to Many, ниже приведен рисунок, который показывает TabularInline с именем: SUBTOPIC-COURSE RELATIONSHIPS.

Я хочу, чтобы можно было добавить подтему через здесь прямо на этой странице

enter image description here

Вот как выглядит мой код admin.py:

class SubTopicInline(admin.StackedInline):
    model = models.SubTopic.course.through


class CourseAdmin(admin.ModelAdmin):
    inlines = [SubTopicInline]


admin.site.register(models.Course, CourseAdmin)

Затем модели:

class Course(TimeStampedModel, models.Model):

    """
    Course model responsible for all courses.

    :cvar uid: UID.
    :cvar title: Course title.
    :cvar description: Description of the course.
    :cvar course_cover: Image for the course.
    :cvar category: Course Category.
    :cvar user: Author of the course.
    :cvar review: Course review.
    """
    uuid = models.UUIDField(unique=True, max_length=500,
                            default=uuid.uuid4,
                            editable=False,
                            db_index=True, blank=False, null=False)
    title = models.CharField(
        _('Title'), max_length=100, null=False, blank=False)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name_plural = "Courses"


class SubTopic(TimeStampedModel, models.Model):
    """
        Subtopic for the course.
    """

    uuid = models.UUIDField(unique=True, max_length=500,
                            default=uuid.uuid4,
                            editable=False,
                            db_index=True, blank=False, null=False)
    sub_topic_cover = models.ImageField(
        _('Sub topic Cover'), upload_to='courses_images',
        null=True, max_length=900)
    title = models.CharField(
        _('Title'), max_length=100, null=False, blank=False)
    course = models.ManyToManyField(Course, related_name='sub_topic',
                                    blank=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name_plural = "Sub topic"


class Lesson(TimeStampedModel, models.Model):

    """
    Lesson for the sub topic.
    """
    uuid = models.UUIDField(unique=True, max_length=500,
                            default=uuid.uuid4,
                            editable=False,
                            db_index=True, blank=False, null=False)
    subtopic = models.ManyToManyField(SubTopic, related_name='lessons',
                                      blank=True)
    video_link = models.CharField(
        _('Video Link'), max_length=800, null=False, blank=False)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name_plural = "Lesson"
Вернуться на верх