V
V
Villian_Os2020-07-07 10:42:16
Django
Villian_Os, 2020-07-07 10:42:16

Why doesn't the django admin site add an entry section for the model?

5f042672b1bc5685217303.png
The section for Advertisement does not appear on the site, although everything seems to be entered correctly.
There is a model file: model.py

from django.db import models


class Advertisement(models.Model):
    title = models.CharField(max_length=1000)
    description = models.CharField(max_length=1000, default='', verbose_name='Описание')
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    price = models.FloatField(verbose_name='Цена', default=0)
    views_count = models.IntegerField(verbose_name='Количество просмотров', default=0)
    status = models.ForeignKey('AdvertisementStatus', default=None, null=True, on_delete=models.CASCADE,
                               related_name='advertisements', verbose_name='Статус')

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'advertisements'
        ordering = ['title']


class AdvertisementStatus(models.Model):
    name = models.CharField(max_length=100)

    def __str__(self):
        return self.name


And admin.py :
from django.contrib import admin
from .models import *


@admin.register(Advertisement)
class AdvertisementAdmin(admin.ModelAdmin):
    pass

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey Tikhonov, 2020-07-07
@tumbler

default_app_config should be written

L
Larisa .•º, 2020-07-07
@barolina

try like this
admin.site.register(Advertisement)

V
Vadim Shatalov, 2020-07-07
@netpastor

Is the application with this model definitely included in INSTALLED_APPS in the settings?

S
soremix, 2020-07-07
@soremix

If you import a specific model? Have you already done reloading the application / hard reload in the browser, as I understand it? Although it should load without it
from .models import Advertisement

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question