Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7094129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:31:31+00:00 2026-05-28T08:31:31+00:00

I would like to be able to add inline Image objects to Gallery in

  • 0

I would like to be able to add inline Image objects to Gallery in Admin (as I try it in admin.py below). Problem is that Image model doesn’t have content_type field. It raises exception. I would like to do the same with Videos objects. Here are my models.py and admin.py and more description below

My models.py

# -*- coding: utf-8 -*-

# Create your models here.
from apps.util import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.utils.translation import ugettext_lazy as _


class Image(models.Model):
    """

    """
    title = models.CharField(_('Title'), max_length=255)
    image = models.ImageField(upload_to="images")
    pub_date = models.DateTimeField(_('Date published'))           

    def __unicode__(self):
        return self.title

class Video(models.Model):

    title = models.CharField(_('Title'), max_length=255)
    video = models.FileField(upload_to="videos")
    pub_date = models.DateTimeField(_('Date published'))

    def __unicode__(self):
        return self.title 

class Gallery(models.Model):

    title = models.CharField(_('Title'), max_length=255)
    pub_date = models.DateTimeField(_('Date published'))

    def __unicode__(self):
        return self.title

class GalleryItem(models.Model):
    gallery = models.ForeignKey(Gallery)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')

    def __unicode__(self):
        return str(self.object_id)  

My admin.py

from django.contrib import admin
from apps.webmachinist.media.models import *
from apps.webmachinist.portfolio.models import *
from django.contrib.contenttypes import generic

class GalleryInline(generic.GenericTabularInline):
    model = Image

class GalleryAdmin(admin.ModelAdmin):
    inlines = [
        GalleryInline,
    ]

admin.site.register(Image)
admin.site.register(Video)
admin.site.register(Gallery, GalleryAdmin)
admin.site.register(GalleryItem)
admin.site.register(PortfolioEntry)

I can do it easily in reverse way: to add Gallery to an Image, like that:

class GalleryInline(generic.GenericTabularInline):
    model = GalleryItem

class GalleryAdmin(admin.ModelAdmin):
    inlines = [
        GalleryInline,
    ]

admin.site.register(Image, GalleryAdmin)

Then I can choose by Gallery title, though inline is for GalleryItems
But it’s not what I want. I just want to add Images to Galleries (and later Videos) not Galleries to Images.

Can it be done easily?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:31:31+00:00Added an answer on May 28, 2026 at 8:31 am

    You shouldn’t be inlining Image, but rather GalleryItem. Then from each GalleryItem you can associate it with whatever through it’s generic foreign key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ObservableCollection that I would like to be able to add and
I would like to be able to add a message to a unit test,
I would like to be able to add a new SQL LOGIN and name
I would like to be able to add a click event to a entity
I would like to add a uitoolbar able to slide -in from the top
I would like to call the pow function from inline assembly. The problem is
So I have a page where I would like to be able to add
I would like to be able to add UIImageViews to my screen and also
I would like to be able to add a score, in a different view
I would like to be able to add a custom field to folders in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.