new model does not show up in admin

21 views
Skip to first unread message

ihome

unread,
Jul 22, 2008, 11:45:37 PM7/22/08
to Django users
Hi,

I am following the examples in book: practical django projects using
latest dev version of django.

In the third chaper: CMS example, a new SearchKeyword class is added
as follows:

from django.db import models
from django.contrib.flatpages.models import FlatPage

class SearchKeyword(models.Model):
keyword = models.CharField(max_length=50)
page = models.ForeignKey(FlatPage)

class Admin:
pass

def __unicode__(self):
return self.keyword

I also added "cms.search" application in the settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.flatpages',
'cms.search',
)

Then I ran the "manager.py syndb", it shows:

Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for admin.LogEntry model
Installing index for flatpages.FlatPage model
Installing index for search.SearchKeyword model

But once the local server was started, on django admin, I could only
see all the other models except for the one: search.SearchKeyword

Isn't
class Admin:
pass
enough to add a new model into admin interface?

Any help?

Thanks.

Eric Abrahamsen

unread,
Jul 23, 2008, 12:17:26 AM7/23/08
to django...@googlegroups.com

On Jul 23, 2008, at 11:45 AM, ihome wrote:
>
>
> Isn't
> class Admin:
> pass
> enough to add a new model into admin interface?

If you're using a very recent (past week or so) checkout of the django
trunk, then you're using newforms admin, which is significantly
different from the oldforms admin system. Instructions are here:

http://www.djangoproject.com/documentation/admin/

Yours,
Eric

Russell Keith-Magee

unread,
Jul 23, 2008, 12:26:01 AM7/23/08
to django...@googlegroups.com
On Wed, Jul 23, 2008 at 11:45 AM, ihome <ihome...@gmail.com> wrote:
>
> Hi,
>
> I am following the examples in book: practical django projects using
> latest dev version of django.

Hi,

If you're running the latest dev version of Django, the advice given
by Practical Django Projects will unfortunately be a little out of
date. In particular, the admin application has recently gone through
some very big changes, and the way you register applications with the
admin has changed somewhat. For details on what has changed and how to
migrate, try the following:

http://code.djangoproject.com/wiki/NewformsHOWTO
http://oebfare.com/blog/2008/jul/20/newforms-admin-migration-and-screencast/

The Django Admin documentation may also be usefule:

http://www.djangoproject.com/documentation/admin/

More generally, any changes that are made to Django that are backwards
incompatible in some way are described here:

http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges

If you update a 'trunk' install of Django and things start to break,
this is the first place to check.

Yours,
Russ Magee %-)

michael...@gmail.com

unread,
Jul 23, 2008, 11:36:30 PM7/23/08
to Django users
*WHEW* So THAT'S what's going on w/ my models. I checked out a version
early this week to follow a couple of tutorials and have had the same
problem. Good luck if you're a newbie and following a book or blog -
even one straight from the core team (hello, Django Book).

Thank god for Google Groups and active core developers. And thanks for
helping out, Russ.

Mike

On Jul 23, 12:26 am, "Russell Keith-Magee" <freakboy3...@gmail.com>
wrote:
> If you're running the latest dev version of Django, the advice given
> by Practical Django Projects will unfortunately be a little out of
> date. In particular, the admin application has recently gone through
> some very big changes, and the way youregisterapplications with the
> admin has changed somewhat. For details on what has changed and how to
> migrate, try the following:

<snip>

> Yours,
> Russ Magee %-)

eoc

unread,
Jul 26, 2008, 5:46:11 PM7/26/08
to Django users
I'm running into the same issue going through the book. I am wondering
if there is any place to see the example in the book on page 37 re-
implemented correctly running from django-trunk. I admit I'm a newbie
at this but I keep running into this same wall with Django (changes
between tutorials and the current way of doing things) - So I was glad
to see the Practical Django Projects book when it came out since I
wanted to take another run at it, and now I'm just feeling stupid
again.

I followed the screencast from the link above (thank you) and I am
understanding the changes conceptually, but just can't seem to make
the book example work. I have created a new admin.py file in my search
app and have adapted the screencast methods to the model
(SearchKeyword). SearchKeyword is to be an inline to django's
FlatPages. So I currently have this class in my models.py:

from django.db import models
from django.contrib import admin
from django.contrib.flatpages.models import FlatPage

class SearchKeyword(models.Model):
keyword = models.CharField(max_length=50)
page = models.ForeignKey(FlatPage)

def __unicode__(self):
return self.keyword

and I have the following in my admin.py:

from django.contrib import admin
from cms.search.models import SearchKeyword
from django.contrib.flatpages.models import FlatPage

class SearchKeywordInline(admin.StackedInline):
model = SearchKeyword


class FlatPageAdmin(admin.ModelAdmin):
inlines = [
SearchKeywordInline,
]

admin.site.register(SearchKeyword, FlatPageAdmin)

-- So, currently, I am currently getting a standalone Search and
SearchKeywords available to me in my admin index, but not inline to
FlatPage. (actually adding a keyword this way errors out anyway). And
based on the code above, I don't see how it would be associated with
the built-in flatpage object anyway.

Any insights would be greatly appreciated and will help me feel a bit
less demoralized :) Sorry for the super long post.
-Eric


nichols

unread,
Jul 26, 2008, 11:12:47 PM7/26/08
to Django users
Check out: http://blog.cottee.org/2008_07_01_archive.html

Basically, all you have to do is unregister the FlatPage model in the
admin.py before you register the new FlatPageAdmin

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)

Also, there's no reason to register the SearchKeyword class, since
it's now tied to the FlatPage admin.

eoc

unread,
Jul 27, 2008, 9:05:31 PM7/27/08
to Django users
On Jul 26, 8:12 pm, nichols <dnicho...@gmail.com> wrote:
> Check out:  http://blog.cottee.org/2008_07_01_archive.html
>
> Basically, all you have to do is unregister the FlatPage model in the
> admin.py before you register the new FlatPageAdmin
>
> admin.site.unregister(FlatPage)
> admin.site.register(FlatPage, FlatPageAdmin)
>
> Also, there's no reason to register the SearchKeyword class, since
> it's now tied to the FlatPage admin.

Ahh, thank you so much. You have been enormously helpful, and I really
appreciate it.
Thank you!

datdesignguy

unread,
Aug 3, 2008, 8:24:59 AM8/3/08
to Django users
Thank you!

I'd been scratching my head at this same issue for an hour or two.

Loving Django, but wondering if I should just be doing the SVN User
Guide to learn Django instead of the Practical Django book, as I'm
using the trunk version with newforms.

Anyway, Thanks again for posting this solution :-)

On Jul 26, 8:12 pm, nichols <dnicho...@gmail.com> wrote:
> > FlatPage. (actuallyaddinga keyword this way errors out anyway). And
Reply all
Reply to author
Forward
0 new messages