Note that there are some explanatory texts on larger screens.

plurals
  1. POAlternative to django concrete inheritance
    primarykey
    data
    text
    <p>I have a Django model class which encompass various types of model classes like:</p> <pre><code>Content &gt; (Audio, Video, Image) </code></pre> <p>I want to perform queries on this parent model like Content.objects.filter() or Content.objects.recent(). How do i come about this? Presently i am using django's concrete model inheritance, which I suppose impose lot of overheard on the db performance by using joins for the parent classes. I cannot use abstract class because that would not permit me to perform queries on the parent class. Here are my models definitions:</p> <pre><code>class BaseContent(models.Model): """ Concrete base model to encompass all the local and social content. We need a single queryset for all the content on the app. """ title = models.CharField(_('title'), max_length=255, default='') description = models.TextField(_('description'), default='', blank=True) publisher = models.ForeignKey(settings.AUTH_USER_MODEL) allow_comments = models.BooleanField(default=False) is_public = models.BooleanField(default=True) created = AutoCreatedField(_('created')) objects = BaseContentManager() class Video(BaseContent): ACTIVITY_ACTION = 'posted a video' UPLOAD_TO = 'video_files/%Y/%m/%d' PREVIEW_UPLOAD_TO = 'video_frames/%Y/%m/%d' video_file = models.FileField(_('video file'), upload_to=UPLOAD_TO) preview_frame = models.ImageField( _('Preview image'), upload_to=PREVIEW_UPLOAD_TO, blank=True, null=True) category = models.ForeignKey(VideoCategory, blank=True, null=True) num_plays = models.PositiveIntegerField(blank=True, default=0) num_downloads = models.PositiveIntegerField(blank=True, default=0) </code></pre> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload