Hey Karen,

I realized that I shouldn't have been using a generic.StackedInline
and fixed the indentation. I left the FlatPage out of register because
I was getting 'The model FlatPage is already registered'.

On Nov 11, 9:09 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Wed, Nov 11, 2009 at 10:40 PM, neridaj <neri...@gmail.com> wrote:
> > I'm doing something wrong when I try to register models for the admin
> > interface and I'm not sure what it is. I have everything in my
> > installed apps, is there something wrong with these files?
>
> > [snip]
> > 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
>
> As someone else already mentioned, this __unicode__ method is not indented
> properly.  It needs to be indented at the same level as the field
> definitions for the model.  The effect of having it the way it is will be
> that SearchKeywords will display using the default unicode() method for a
> model instead of your customized one.
>
>
>
> > search/admin.py
>
> > from testproject.search.models import SearchKeyword
> > from django.contrib.flatpages.models import FlatPage
> > from django.contrib import admin
> > from django.contrib.contenttypes import generic
>
> > class KeywordInline(generic.GenericStackedInline):
> >    model = SearchKeyword
>
> Why are you using a GenericStackedInline here?  You do not have a
> GenericForeignKey in the SearchKeyword model, just a regular ForeignKey.
> admin.StackedInline is what you want for a regular ForeignKey.  (You aren't
> getting far enough to see a problem resulting from this, but you will when
> you fix the error you are hitting, unless you are really using a
> GenericForeignKey in SearchKeyword.)
>
> > class PageAdmin(admin.ModelAdmin):
> >    inlines = [
> >        KeywordInline,
> >    ]
>
> > admin.site.register(PageAdmin)
>
> The first positional argument to admin.site.register is a model (or a
> sequence of models).  You've not specified the model, only the ModelAdmin.
> You need to add a first argument here to specify the model you are
> registering (I'd guess FlatPage, since that is what your inlines have a
> ForeignKey pointing to.)
>
> Karen

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.


Reply via email to