Today I was thinking about the way that we can implement categories/
tags/whatever. Over the last few weeks I have been working on my
category model and essentially creating a generic foreign key to point
to any possible object that we might want to to have categorized.
Problem is Django has a great generic relationship set up, but there
is no generic foreign key field yet. Django-tagging got around this
problem by implement a custom CharField that has a signal attached to
it that breaks apart the words and adds them as tags in a class called
TaggedItem that has a connection to Tag, etc. etc.-- you guys can look
at that code if you want to.
The category layout is simple. Just a category name, title and parent.
I then have a category item that provided the generic relationship and
a manytomany relationship to the category. A lesser roadblock that I
hit was the fact that every item that should be tagged/categorized/
whatever needs to have the CategoryItem related to it, essentially
creating a duplicate field for every categorized/tagged... item.
Almost like an angel from the djangoGods, Malcolm wrote a post today,
http://groups.google.com/group/django-users/browse_frm/thread/6a275999abab2e66
, saying that queryset-refactoring was almost ready to be merged. One
thing that QSRF brings to the table is model inheritance,
http://code.djangoproject.com/browser/django/branches/queryset-refactor/docs/model-api.txt#L2085
. This would be perfect for the category relationship that I was
trying to create. So I implemented this on my category model without
problems. I am writing up some tests as we speak, and I plan on
implementing it on my non-existant blog tonight, so I hope that it
would be thoroughly tested in the next few days.
I wanted to know if we wanted to take this a step further and create a
base class for all of the items that might be indexible throughout
penny-press. We wanted to have all items with categories, sections.
All items can have comments, an active and disabled status, a slug, a
pub_date. All this stuff can be inherited via a penny-press base class
or classes that can provide a really nice entry API, because
everything would start out on the same level when searched.
With this base class we can easily find related items, have inline
sections and really explore the inheritance route.
I will upload the CategoryBase class complete with tests this evening
and I will start writing up a Penny-Press base class this week so we
can see what we think of it. Also we need to make sure to test this
fully because this is a new django feature that I know the core devs
have been struggling with for a while.
What do you guys think, any suggestions?