Announcing djeneralize

16 views
Skip to first unread message

Euan Goddard

unread,
Jan 25, 2011, 6:43:35 AM1/25/11
to Django users
Hi,

I've recently been working on an open source project to augment the
inheritance of models in Django. This project, called "djeneralize"
allows you to declare specializations on your models and then query
the general case model and get back the specialized instances. A
simple example of the models might be:

class Fruit(BaseGeneralizedModel):
name = models.CharField(max_length=30)

def __unicode__(self):
return self.name

class Apple(Fruit):
radius = models.IntegerField()

class Meta:
specialization = 'apple'

class Banana(Fruit):
curvature = models.DecimalField(max_digits=3, decimal_places=2)

class Meta:
specialization = 'banana'

class Clementine(Fruit):
pips = models.BooleanField(default=True)

class Meta:
specialization = 'clementine'

which then allows the following queries to be executed:

>>> Fruit.objects.all() # what we've got at the moment
[<Fruit: Rosy apple>, <Fruit: Bendy banana>, <Fruit: Sweet
clementine>]
>>> Fruit.specializations.all() # the new stuff!
[<Apple: Rosy apple>, <Banana: Bendy banana>, <Clementine: Sweet
clementine>]

I hope this type of general case/specialization might be of some use
to someone else out there. We're planning on integrating this work in
a large project we're undertaking on content categorization.

Grab the source at github: https://github.com/2degrees/djeneralize

or you can easy_install it (easy_install djeneralize).

Feedback, etc. very welcome.

Thanks, Euan

Manoj Kumar

unread,
Jan 25, 2011, 6:50:38 AM1/25/11
to django...@googlegroups.com
Hi Euan,
            Impressive work.


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




--
Thanks & Regards

Manoj Kumar


Tom Evans

unread,
Jan 25, 2011, 9:26:17 AM1/25/11
to django...@googlegroups.com
On Tue, Jan 25, 2011 at 11:43 AM, Euan Goddard <euan.g...@gmail.com> wrote:
> Hi,
>
> I've recently been working on an open source project to augment the
> inheritance of models in Django. This project, called "djeneralize"
> allows you to declare specializations on your models and then query
> the general case model and get back the specialized instances. A
> simple example of the models might be:
>

Hi Euan, sounds good.

Had you come across django_polymorphic[1]? This library also covers
similar goals.

Cheers

Tom

[1] http://bserve.webhop.org/django_polymorphic/

Euan Goddard

unread,
Jan 25, 2011, 9:49:21 AM1/25/11
to Django users
Hi Tom,

I hadn't seen that. django_polymorphic looks pretty fully featured and
from a quick look, I'd say it accomplishes everything we set out to
do. I guess a use case for djeneralize would be to handle the simple
specializations and generalizations and nothing more. The impetuous to
write the package was just to augment Django's model inheritance which
did almost everything we needed.

Thanks again for the link.

Euan

On Jan 25, 2:26 pm, Tom Evans <tevans...@googlemail.com> wrote:

sebastien piquemal

unread,
Jan 25, 2011, 11:08:13 AM1/25/11
to Django users
Great packages ...

I was looking for something exactly similar for a project I am working
on. I will surely use one of those !
Reply all
Reply to author
Forward
0 new messages