Kieran,

It looks like a ticket for my particular problem. While I do use a 
"recursive parent field", I hesitated to subclass it. I'll give it a try.

Thanks,

Eugene

"Kieran Holland" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Eugene,

On 05/09/05, Eugene Lazutkin <[EMAIL PROTECTED]> wrote:

> One possible solution is to create Category model and subclass it every 
> time
> I need to use it. Subclassed model should live in its own table and
> implement proper getters to get related objects. I don't know if it is
> possible now. If it is possible, it is not explained how to do it. I hope
> somebody will explain it to me.

Subclassing models is possible in Django.  Instances of subclasses are
stored in a new table, independent of the superclass.  There are some
docs here:

http://www.djangoproject.com/documentation/models/subclassing/

To allow for hierarchical categories your category model could perhaps
include a recursive  parent field:

class Category(meta.Model):
    ...etc.
    parent = meta.ForeignKey('self', blank=True, null=True)     # note
that self is quoted

with NULL-parented fields representing base categories.  Your blog
entry model would then include a ManyToMany field relating to
categories:

class BlogEntry(meta.Model):
    ...etc.
    categories = meta.ManyToManyField(Category,
filter_interface=meta.HORIZONTAL)

The filter_interface argument gives you a nice little javascript-based
interface for applying categories to your entries.

Might do what you want,
Kieran



Reply via email to