[Django] Brak możliwości zarządzanie modelami w panelu admina

Korzystam z Django 1.6 i Postgresa. Chciałbym skorzystać z panelu admina do edycji modeli w panelu administratora. Tworzę nową aplikację, wykonuje polecenie syncdb, a następnie tworzę plik models.py z wykorzystaniem polecenia inspectdb. Następnie tworzę plik admin.py i rejestruje interesujące mnie modele, niestety mój panel admina wciąż nie pokazuje wskazanych modeli. Co może być problemem? Tworzył również nowy projekt i wciąż to samo.

 

admin.py

from django.contrib import admin
from models import Wpisy
 
admin.site.registry(Wpisy)

 

models.py - wygenerowany automatycznie, nie patrzcie na sens takiego rozwiązania, baza jest tymczasowa na potrzeby testów z django

# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#   * Rearrange models' order
#   * Make sure each model has one field with primary_key=True
#   * Remove `managed = False` lines if you wish to allow Django to create and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
# into your database.
from __future__ import unicode_literals
 
from django.db import models
 
class AuthGroup(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=80)
    class Meta:
        managed = False
        db_table = 'auth_group'
 
class AuthGroupPermissions(models.Model):
    id = models.IntegerField(primary_key=True)
    group = models.ForeignKey(AuthGroup)
    permission = models.ForeignKey('AuthPermission')
    class Meta:
        managed = False
        db_table = 'auth_group_permissions'
 
class AuthPermission(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=50)
    content_type = models.ForeignKey('DjangoContentType')
    codename = models.CharField(max_length=100)
    class Meta:
        managed = False
        db_table = 'auth_permission'
 
class AuthUser(models.Model):
    id = models.IntegerField(primary_key=True)
    password = models.CharField(max_length=128)
    last_login = models.DateTimeField()
    is_superuser = models.BooleanField()
    username = models.CharField(max_length=30)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    email = models.CharField(max_length=75)
    is_staff = models.BooleanField()
    is_active = models.BooleanField()
    date_joined = models.DateTimeField()
    class Meta:
        managed = False
        db_table = 'auth_user'
 
class AuthUserGroups(models.Model):
    id = models.IntegerField(primary_key=True)
    user = models.ForeignKey(AuthUser)
    group = models.ForeignKey(AuthGroup)
    class Meta:
        managed = False
        db_table = 'auth_user_groups'
 
class AuthUserUserPermissions(models.Model):
    id = models.IntegerField(primary_key=True)
    user = models.ForeignKey(AuthUser)
    permission = models.ForeignKey(AuthPermission)
    class Meta:
        managed = False
        db_table = 'auth_user_user_permissions'
 
class DjangoAdminLog(models.Model):
    id = models.IntegerField(primary_key=True)
    action_time = models.DateTimeField()
    user = models.ForeignKey(AuthUser)
    content_type = models.ForeignKey('DjangoContentType', blank=True, null=True)
    object_id = models.TextField(blank=True)
    object_repr = models.CharField(max_length=200)
    action_flag = models.SmallIntegerField()
    change_message = models.TextField()
    class Meta:
        managed = False
        db_table = 'django_admin_log'
 
class DjangoContentType(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=100)
    app_label = models.CharField(max_length=100)
    model = models.CharField(max_length=100)
    class Meta:
        managed = False
        db_table = 'django_content_type'
 
class DjangoSession(models.Model):
    session_key = models.CharField(max_length=40)
    session_data = models.TextField()
    expire_date = models.DateTimeField()
    class Meta:
        managed = False
        db_table = 'django_session'
 
class Kategorie(models.Model):
    id = models.IntegerField(primary_key=True)
    nazwa = models.CharField(max_length=50, blank=True)
    class Meta:
        managed = False
        db_table = 'kategorie'
 
class Wpisy(models.Model):
    id = models.IntegerField(primary_key=True)
    tekst = models.CharField(max_length=400, blank=True)
    class Meta:
        managed = False
        db_table = 'wpisy'

settings.py:

"""
Django settings for mysite project.
 
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
 
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
 
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname( __file__ ))
 
 
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
 
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '6cx2ie!8#jy=a8zby7m*9wzcwcip6f_f^kalf_qi8d^pl#18te'
 
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
 
TEMPLATE_DEBUG = True
 
ALLOWED_HOSTS = []
 
 
# Application definition
 
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)
 
MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)
 
ROOT_URLCONF = 'mysite.urls'
 
WSGI_APPLICATION = 'mysite.wsgi.application'
 
 
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
 
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'test2',                      
        'USER': 'postgres',
        'PASSWORD': 'sql',
        'HOST': '127.0.0.1'
    }
}
 
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
 
LANGUAGE_CODE = 'en-us'
 
TIME_ZONE = 'UTC'
 
USE_I18N = True
 
USE_L10N = True
 
USE_TZ = True
 
 
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
 
STATIC_URL = '/static/'

za https://docs.djangoproject.com/en/1.6/intro/tutorial02/#enter-the-admin-site

w admin.py powinno być “register” zamiast Twojego “registry”

Zmieniłem, niestety wciąż nie widzę modelu w panelu admina :frowning:

Gdzie masz ten plik models.py? Bo IMHO powinno być w katalogu aplikacji (np. “forum”), a jej nazwa dodana do listy INSTALLED_APPS

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'forum',
)

No i sam import w models.py powinien wyglądać tak:

from forum.models import Wpisy

Czy może inaczej, nie wiem - Django Newbie jestem :slight_smile:

Przerzucałem pomiędzy folderami, dodawałem i usuwałem z “zainstalowanych” - i nic :confused: Siedzę nad tym od wczoraj i nie mam pojęcia co jest nie tak. Co ciekawe kod utworzy w starym django (1.4.7) działa ok.

a czy to “managed = False” dla Wpisy.Meta jest pożądane? https://docs.djangoproject.com/en/dev/ref/models/options/#managed

 

 

Nie, po prostu próbowałem już wszystkiego.

 

Rozwiązaniem okazało się być proste. W zainstalowanych aplikacjach w settings.py nie potrzebnie odnosiłem się do katalogu, w którym jest aplikacja (tak robiłem od samego początku walki z django i działało). Teraz wystarczyło dodać po prostu nazwę aplikacji i ruszyło :wink:

 

Dzięki za pomoc :wink: