Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In django admin panel can't add and change my model objects

In my django admin panel there are four items: "Groups", "Users", "Sites", and my custom model "Ads". All of it has button "Add" and "Change". System items' button works as usual. And my model's button "Add" redirect on blank page with title "add (1x1)", button "Change" redirect on blank page with title "ad (1x1)".

It happens even when I create project from Django tutorial https://docs.djangoproject.com/en/1.4/intro/tutorial01/

I use django's development server.

models.py

from django.db import models

class Ad(models.Model):
    text = models.TextField()  
    tel = models.CharField(max_length=12)   
    pub_date = models.DateTimeField(auto_now_add=True)  
    checked = models.BooleanField(default=False)

    def __unicode__(self):
        return self.text[0:20]

admin.py

from models import Ad
from django.contrib import admin

admin.site.register(Ad)

Very simple code.

How to get normal Add and Change pages?

UPD: System - Windows, browsers - Chrome, Firefox, Opera

like image 573
Sergey Simonyan Avatar asked Feb 20 '23 09:02

Sergey Simonyan


1 Answers

I was seeing all the models in the admin but none of them were editable. I had no available actions. My urls.py looked normal to me:

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
)

admin.autodiscover()

I moved admin.autodiscover() to the top of the file, before the urlpatterns declaration, and everything started working normally:

from django.conf.urls import patterns, include, url
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
)
like image 104
Krystian Cybulski Avatar answered Feb 22 '23 04:02

Krystian Cybulski