Re: Including apps for inherited models in INSTALLED_APPS

2011-02-08 Thread Shawn Milochik
On Tue, Feb 8, 2011 at 9:39 AM, Ian Stokes-Rees
 wrote:
> I'm (reasonably) happy to include base models in INSTALLED_APPS, but
> this argument:
>
> On 2/8/11 4:32 AM, Tom Evans wrote:
>> Explicit is better than implicit. If you want models from app 'base'
>> installed on your system, you add the 'base' app to INSTALLED_APPS.
>> Otherwise, its a series of $MAGIC working out what apps/DB tables are
>> required, and $MAGIC is never good - might as well be using rails.
>
> feels fairly arbitrary -- the whole point of a web framework like Django
> is that "magic happens", and stuff "just works".
>
> Ian
>

As someone for whom performing magic is a hobby, I'm compelled to
point out this secret all magicians know:

There's no such thing as magic.

Therefore, if you want the appearance of magic you must be
well-prepared. If you "look at the other hand" when Django's magic
happens with model inheritance, you'll see contenttypes doing its
dirty work.

Shawn

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



Re: Including apps for inherited models in INSTALLED_APPS

2011-02-08 Thread Ian Stokes-Rees
I'm (reasonably) happy to include base models in INSTALLED_APPS, but
this argument:

On 2/8/11 4:32 AM, Tom Evans wrote:
> Explicit is better than implicit. If you want models from app 'base'
> installed on your system, you add the 'base' app to INSTALLED_APPS.
> Otherwise, its a series of $MAGIC working out what apps/DB tables are
> required, and $MAGIC is never good - might as well be using rails.

feels fairly arbitrary -- the whole point of a web framework like Django
is that "magic happens", and stuff "just works".

Ian

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



Re: Including apps for inherited models in INSTALLED_APPS

2011-02-08 Thread Tom Evans
On Mon, Feb 7, 2011 at 8:28 PM, Ian Stokes-Rees
 wrote:
> Does it make sense that inherited models also need their apps included in
> INSTALLED_APPS?  Right now if I have:
>
> base/models.py:
>
> class MyBaseModel(django.db.models.Model):
>    stuff
>
> and then elsewhere:
>
> derived/models.py:
>
> class MyDerivedModel(base.MyBaseModel):
>    stuff
>
> I need to include both "derived" and "base" in my INSTALLED_APPS list in
> settings.py, otherwise the table for the MyBaseModel content is never
> created.  It seems to me that "syncdb" should be able to "see" that
> MyDerivedModel has MyBaseModel as a super class in the chain to
> django.db.models.Model and consequently create the necessary tables for
> MyBaseModel.
>
> Or have I just misunderstood why it was necessary for me to include "base"
> in order to get the tables created properly by "manage.py syncdb"?
>
> TIA, Ian Stokes-Rees
>

Explicit is better than implicit. If you want models from app 'base'
installed on your system, you add the 'base' app to INSTALLED_APPS.
Otherwise, its a series of $MAGIC working out what apps/DB tables are
required, and $MAGIC is never good - might as well be using rails.

Cheers

Tom

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



Re: Including apps for inherited models in INSTALLED_APPS

2011-02-07 Thread Shawn Milochik
Perhaps some deeper background will help:

http://docs.djangoproject.com/en/1.2/ref/contrib/contenttypes/

Shawn

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



Re: Including apps for inherited models in INSTALLED_APPS

2011-02-07 Thread Ian Stokes-Rees


On 2/7/11 3:50 PM, Shawn Milochik wrote:
> Because when the model isn't abstract, the fields
> in the base model aren't created for the subclass -- the subclass has
> a foreign key to an instance of the base model.
> That last bit should explain why you need to have the base app in
> installed apps.

Not really -- it explains why adding it makes things work, but it
doesn't explain why I *have* to include it.  "syncdb" is smart enough to
figure out that DerivedModel(BaseModel) has django.db.models.Model
*somewhere* in its super-class ancestry, so I don't see why it can't
also be smart enough to then figure out that "BaseModel" needs to be
included for ORM automatically.

Ian

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



Re: Including apps for inherited models in INSTALLED_APPS

2011-02-07 Thread Shawn Milochik
On Mon, Feb 7, 2011 at 3:43 PM, Ian Stokes-Rees
 wrote:
> On 2/7/11 3:38 PM, Shawn Milochik wrote:
>> Is your base model abstract? If it is not, then the ORM will want to
>> create it in the database.
>
> No, it isn't abstract.  It has a particular content model and methods
> associated with it.  When you say the ORM will "want" to create it in
> the DB, do you mean:
>
> 1. It should figure this out on its own and create the base model table; or
> 2. The ORM needs this so it must be listed in INSTALLED_APPS to have the
> relevant table created in the DB.
>


It's definitely #2. Because when the model isn't abstract, the fields
in the base model aren't created for the subclass -- the subclass has
a foreign key to an instance of the base model.
That last bit should explain why you need to have the base app in
installed apps.

Shawn

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



Re: Including apps for inherited models in INSTALLED_APPS

2011-02-07 Thread Ian Stokes-Rees
On 2/7/11 3:38 PM, Shawn Milochik wrote:
> Is your base model abstract? If it is not, then the ORM will want to
> create it in the database.

No, it isn't abstract.  It has a particular content model and methods
associated with it.  When you say the ORM will "want" to create it in
the DB, do you mean:

1. It should figure this out on its own and create the base model table; or
2. The ORM needs this so it must be listed in INSTALLED_APPS to have the
relevant table created in the DB.

Right now it looks like the situation is 2., but I'm wondering if there
is a good reason why it can't be 1.

Thanks,

Ian

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



Re: Including apps for inherited models in INSTALLED_APPS

2011-02-07 Thread Shawn Milochik
Is your base model abstract? If it is not, then the ORM will want to
create it in the database.

Shawn

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



Including apps for inherited models in INSTALLED_APPS

2011-02-07 Thread Ian Stokes-Rees
Does it make sense that inherited models also need their apps included in 
INSTALLED_APPS?  Right now if I have:

base/models.py:

class MyBaseModel(django.db.models.Model):
   stuff

and then elsewhere:

derived/models.py:

class MyDerivedModel(base.MyBaseModel):
   stuff

I need to include both "derived" and "base" in my INSTALLED_APPS list in 
settings.py, otherwise the table for the MyBaseModel content is never 
created.  It seems to me that "syncdb" should be able to "see" that 
MyDerivedModel has MyBaseModel as a super class in the chain to 
django.db.models.Model and consequently create the necessary tables for 
MyBaseModel.

Or have I just misunderstood why it was necessary for me to include "base" 
in order to get the tables created properly by "manage.py syncdb"?

TIA, Ian Stokes-Rees

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