On Thu, Apr 15, 2010 at 1:58 AM, Victor Hooi <victorh...@gmail.com> wrote:

> heya,
>
> We're creating a small app to manage data-entry of publicat articles
> in Django.
>
> Each article has a category, a subject, a list of firms (as in the
> companies mentioned), etc.
>
> I'm trying to add firm as an inline to article, however, I think I've
> got the ordered in the model all wrong, as it's telling me:
>
> <class 'mediatracking.articles.models.Category'> has no ForeignKey to
> <class 'mediatracking.articles.models.Article'>
>

Your text says something about 'firm' but the error message and the defs you
provide are all about Category...?


> Basically, each article can have one category, but there's obviously
> many articles to each category.
>
> An excerpt from models.py:
>
> class Category(models.Model):
>    name = models.CharField(max_length=25)
>
>    def __unicode__(self):
>        return self.name
>
>    class Meta:
>        verbose_name_plural = "categories"
> ....
> class Article(models.Model):
>    title = models.CharField(max_length=50)
>    publication_date = models.DateField()
>    abstract = models.TextField() # Can we restrict this to 450
> characters?
>    category = models.ForeignKey(Category)
>    subject = models.ForeignKey(Subject)
>    source = models.ForeignKey(Publication)
>    page_number = models.CharField(max_length=20)
>    url = models.URLField()
>    firm = models.ManyToManyField(Firm)
>    #firm = models.ForeignKey(Firm)
>    spokesperson = models.ManyToManyField(Spokeperson)
>    #spokesperson = models.ForeignKey(Spokeperson)
>
> And admin.py:
>
> class CategoryInline(admin.TabularInline):
>    model = Category
> ...
> class ArticleAdmin(admin.ModelAdmin):
>    inlines = [
>        CategoryInline,
>    ]
> ...
> admin.site.register(Article, ArticleAdmin)
>
>
What your admin definitions are saying is that you want to have, on the edit
page for an Article, an inline list of the Categories that are associated
with (have a ForeignKey pointing to) the article. That's impossible based on
your model definitions, since the ForeignKey for this relationship is in
Article: an Article may have only one Category so it makes no sense to have
Categories inline on the Article edit page.

What you can do with these models as defined is have Articles inline on the
Category edit page. That is, one the edit page for a Category you could have
a list of the Articles in that category. For this you'd have to create an
ArticleInline model and specify it in inlines for the CategoryAdmin class.

[snip the question about command-extensions and m2m since I don't use that
and have no idea of the answer]

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=en.

Reply via email to