On Thu, Jun 12, 2008 at 5:23 AM, Stephan Walter <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I've read several descriptions (on the website and the mailinglist) on
> how inheritance once worked, works now, should work, or does not work,
> and I'm confused...
>

At this point since it's been (re-)implemented, the definitive doc is:

http://www.djangoproject.com/documentation/model-api/#model-inheritance

Stick to that, and you should avoid confusion.  If there is something not
covered by that doc then it should be brought up here so it can be
addressed.

I have an abstract base class called File:
>
>    class File(models.Model):
>        user = models.ForeignKey(User)
>        file = models.FileField(upload_to="uploads/")
>        class Meta:
>            abstract = True
>
> I want to have several classes that inherit from it, for example:
>
>    class BitmapImageFile(File):
>        width = models.IntegerField()
>        height = models.IntegerField()
>
>    class PdfFile(File):
>        num_pages = models.IntegerField()
>
> Now, I'd like to access all the file objects. Ideally, I would write
>    File.objects.all()
> but File does not have an objects property.
>
> Is there a way to do this that will not kill my database performance?
> Maybe an abstract base is the wrong idea...
>
> Any help is appreciated!


>From the page I linked to:

Often, you will just want to use the parent class to hold information that
you don't want to have to type out for each child model. This class isn't
going to ever be used in isolation, so abstract base classes are what you're
after. However, if you're subclassing an existing model (perhaps something
from another application entirely), or want each model to have its own
database table, multi-table inheritance is the way to go.

In your case it sounds like you do want the base model to have its own
database table (so you can write File.objects.all()), so it is not a class
that isn't ever going to be used in isolation.  Therefore it sounds like
multi-table inheritance is what you want to look at using, not an abstract
base class.

Karen

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to