0

I don't have the advertisement module displayed in the django admin panel. Here is the model code

from django.db import models


class Advertisement(models.Model):
    title = models.CharField(max_length=1000, db_index=True)
    description = models.CharField(max_length=1000, default='', verbose_name='description')
    creates_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    price = models.FloatField(default=0, verbose_name="price")
    views_count = models.IntegerField(default=1, verbose_name="views count")
    status = models.ForeignKey('AdvertisementStatus', default=None, null=True, on_delete=models.CASCADE,
                               related_name='advertisements')

    def __str__(self):
        return self.title

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


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

admin.py /

from django.contrib import admin
from .models import Advertisement

admin.site.register(Advertisement)

I was just taking a free course from YouTube. This was not the case in my other projects. Here I registered the application got the name in INSTALLED_APPS. Then I performed the creation of migrations and the migrations themselves. Then I tried to use the solution to the problem here , nothing helped. I didn't find a solution in Google search either.

127.0.0.1:8000/admin/  in browser

console  in pycharm

1 Answers1

2

admins.py

The name of the file is admin.py not admins.py. Yes, that is a bit confusing since most module names in Django are plural. The rationale is probably that you define a (single) admin for the models defined.

Alternatively, you can probably force Django to import this with the AppConfig:

# app_name/apps.py

from django.apps import AppConfig


class AppConfig(AppConfig):
    def ready(self):
        # if admin definitions are not defined in admin.py
        import app_name.admins  # noqa
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555