views:

34

answers:

1

I am essentially creating a blog application in django as a way of learning the ropes and boosting my skill level in django. I basically have a many-to-many relationship that I am having problems with in the admin site. I have two main types, Article and ArticleTag. Many Articles can belong to many ArticleTags, and the relationship should be bidirectional so as to be able to "follow" the relationship from either side.

The problem I am having is that in the admin panel, when I go to create a new Article, it will not allow me to create a new Article without creating a new ArticleTag, which can't be created without creating a new Article, etc. How can I make these work properly and be optional? Also, is there a fairly easy way to create a control to facilitate tagging as per stack overflow or delicious.com? I am fairly new to the admin system :)

+1  A: 

You forgot to specify blank=True in your ManyToManyField declaration:

class Article(models.Model):
    tags = models.ManyToManyField(ArticleTag, blank=True, 
        related_name="articles")

Also, is there a fairly easy way to create a control to facilitate tagging as per stack overflow or delicious.com?

There's nothing built-in, but there are several add-on libraries for Django that do tagging. One of them might fit your needs.

Mike DeSimone
Solved! Thanks a bunch. Do you know of any specific editor for tags that I can simply plug in to the admin page? I just need a text field that supplies auto-suggest, etc.
TK Kocheran
Sorry, no, I haven't hacked the admin itself that much. Again, you might want to look at the various tagging extensions out there and see how they do it.
Mike DeSimone
Thanks a bunch :)
TK Kocheran