models.pyclass Content(models.Model):
lesson_fk = models.ForeignKey('Lesson', on_delete=models.CASCADE)
order = models.PositiveIntegerField(default=0)
content_type = models.ForeignKey(ContentType,
on_delete=models.CASCADE,
limit_choices_to={'model__in': ('text',
'video',
'image',
'file')})
object_id = models.PositiveIntegerField()
item = GenericForeignKey('content_type', 'object_id')
views.pydef lesson(request, lid):
lid_lesson = get_object_or_404(Lesson, id=lid)
contents = lid_lesson.content_set.all()
context = {
'lesson': lid_lesson,
'contents': contents,
}
return render(request, 'course/view_lesson.html', context)
template:
{% for content in contents %}
{{ content.item }}
{% endfor %}
В зависимости от того, какой модели content.item нужно генерировать разные куски кода. Пойду через if, но как узнать content.item — это обьект какой модели?
Подскажите пожалуйста