Answer the question
In order to leave comments, you need to log in
How to display editing of N materials on one page?
Good day.
So what do we have: model Post(models.Model)
class Post(models.Model):
title = models.CharField(verbose_name='Заголовок', max_length=100, null=False, unique=True)
content = models.TextField(verbose_name='Текст')
min_age = models.IntegerField(verbose_name='Возрастной рейтинг', default=0)
image = models.ImageField(verbose_name='Основное изображене', upload_to='news_image')
site_source = models.URLField(verbose_name='Сайт источник', max_length=110)
date_publish = models.DateTimeField('Дата публикации', null=True)
category = models.ForeignKey(Category, verbose_name='Категория', on_delete=models.CASCADE, default=None)
publish_status = models.BooleanField(verbose_name='Опубликован', default=False)
tags = models.ManyToManyField(Tag)
depend_posts = models.ManyToManyField('self')
def __str__(self):
return self.title
class UpdatePostView(UpdateView):
model = Post
form_class = PostForm
template_name = 'mainApp/post_edit_create.html'
success_url = '/admin/news/'
def get_context_data(self, **kwargs):
context = super(UpdatePostView, self).get_context_data(**kwargs)
context['form_vk'] = PostForm
context['depend_posts'] = self.model.objects.get(id=self.kwargs['pk']).depend_posts.values_list()
return context
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question