[Python-il] [pyweb-il:391] Re: [pyweb-il:389] Re: a question re pluggable apps

Shai Berger shai at platonix.com
Tue Sep 1 14:55:09 IDT 2009


I think the recommended approach is to avoid coupling applications. This means 
you should not change the other app nor do o2o mentioning it explicitly, but 
write your extending model so that it's compatible with any model (or, 
perhaps, any model which supplies some interface) and use a generic foreign 
key. This is the approach taken in django.contrib.comments and django-tagging, 
if I'm not mistaken.

Note that generic foreign keys, since they are not supported by any database 
engine, hurt both your performance and your database integrity guarantees. 
This is a classic case of what's known as the "impedance mismatch" -- you get 
a tradeoff between good database work and good software design.

Shai.

On Tuesday 01 September 2009 14:29:32 Itay Donenhirsch wrote:
> hi there,
> is this the accustomed way of extending models? i mean, if I write an
> app that needs to be "plugged into" another app's table, does it
> usually adds a field to the other app's model or does it do the o2o
> thingy?
> thanks
> itay
>
> On Tue, Sep 1, 2009 at 12:53 PM, Idan Gazit<idan at pixane.com> wrote:
> > Ah, just re-read your question and realized it was slightly different.
> >
> > For reusable apps, I guess o2o field might be the best solution.
> > Subclassing User is not a good idea for a reusable app because you might
> > be stepping on the toes of another app.
> >
> > -I
> >
> > On Sep 1, 2009, at 12:23 PM, ofri raviv wrote:
> >> Hi,
> >>
> >> I have a question about pluggable apps design:  many times, you'd like a
> >> new app to add some fields to the basic models you already have. for
> >> example, if I have a users app, and i want to add karma (everything good
> >> you do on the site gives you good karma points, when you post, when your
> >> posts are voted up, etc). it doesn't really matter how the karma app
> >> works, in the end, it has to add a karma field to the user model that is
> >> already defined in another app.
> >>
> >> the solution seems to be, add another model, UserKarma, that has
> >> user = models.OneToOneField(User, primary_key=True,
> >> related_name='karma')
> >>
> >> and then we can use user.karma.foo to access the fields that karma app
> >> added.
> >>
> >> is that a good solution? how is it performance-wise compared to just
> >> adding the fields to User?
>
> >
> _______________________________________________
> Python-il mailing list
> Python-il at hamakor.org.il
> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "PyWeb-IL" group.
To post to this group, send email to pyweb-il at googlegroups.com
To unsubscribe from this group, send email to pyweb-il+unsubscribe at googlegroups.com
For more options, visit this group at http://groups.google.com/group/pyweb-il?hl=en
-~----------~----~----~----~------~----~------~--~---



More information about the Python-il mailing list