V
V
Vladislav ...2021-04-09 08:51:56
Django
Vladislav ..., 2021-04-09 08:51:56

How to make a separate Django page resizable through the admin?

Dear experts, please tell me how to make it possible to change the "About the company" page through the django admin panel without going into the html code of the page in the future, the model created

class About(models.Model):
    title = models.CharField(max_length=255, verbose_name="Каталог")
    slug = models.SlugField(max_length=255, verbose_name="URL", unique=True)
    text = models.TextField(verbose_name='О компании', blank=True)
    image = models.ImageField(upload_to='image/%Y/%m/', verbose_name='Картинка', blank=True)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('catalog', kwargs={"slug": self.slug})

    class Meta:
        verbose_name = 'О компании'
        verbose_name_plural = 'О компании '

vyuha
class AboutBy(DetailView):
    model = About
    template_name = 'about.html'
    context_object_name = 'about'

    def get_context_data(self, *, object_list=None, **kwargs):
        context = super(AboutBy, self).get_context_data(**kwargs)
        context['title'] = 'О компании'
        return context

URL
path('<str:slug>/', AboutBy.as_view(), name='about'),

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2021-04-09
@akula993

https://docs.djangoproject.com/en/3.1/ref/contrib/...

L
Larisa .•º, 2021-04-09
@barolina

and through the standard django-admin tools, django- admin is not suitable

@admin.register(About)
class AboutAdmin(admin.ModelAdmin):
   ....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question