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 6981355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:08:49+00:00 2026-05-27T18:08:49+00:00

I have some models in my app,every one is going to have a set

  • 0

I have some models in my app,every one is going to have a set of images(n images),in order to handle this i designed these models:

class Gallery(models.Model):
   HeadImage = models.ImageField(upload_to="gallery")

class Image(models.Model):
   Image = models.ImageField(upload_to="gallery")
   Gallery = models.ForeignKey(Gallery, related_name='images')

now every model to have n images,will have a foreignkey to Gallery,like thie:

class Tour(models.Model):
   Category=models.ForeignKey(TourCategory)
   Name=models.CharField(max_length=100)
   Count=models.SmallIntegerField() 
   PriceUnit=models.ForeignKey(PriceUnit)
   Price=models.CharField(max_length=12)
   Description=models.TextField()
   Status_Choices=(
      ('a',ugettext_lazy('Activate')),
      ('d',ugettext_lazy('Deactivate')),
   )
   StatusType=models.CharField(max_length=1,choices=Status_Choices)
   Gallery = models.OneToOneField(Gallery,editable=False)
   CHOICES=(
      ('T',ugettext_lazy('yes')),
      ('F',ugettext_lazy('no')),
   )
   isSpecial=models.CharField(max_length=1,choices=CHOICES)

When I add Tour model to admin,I have a combobox for Gallery Field,this combobox doesn’t make sense,like this:
add tour in admin

I don’t wanna use other galleries that have been added already,instead I wanna have a formset like this:
add tour form with formset

Here Head Image is HeadImage field in Gallery model and Image1,Image2,... is an inline Image set for Image model.how can I handle this situation in admin?I wanna ommit that combobox and replace it with this HeadImage and ImageSet.

thanks in advancce


when I change Tour model to this:

class Tour(Gallery):
    ...

I have some thing like this:

enter image description here

while I need n images for each Tour,so that Head Image is the primary image and more Images(related to Image model) are optional and I’m thinking how to bring a formset of Images beside Head Image Field in Add Tour Form.
do U have any solution?

  • 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-27T18:08:49+00:00Added an answer on May 27, 2026 at 6:08 pm

    If the form you’ve provided is accurate, ‘Tour’ doesn’t contain a gallery, it implements a gallery. Therefore, you’ll probably have better luck using Django’s multi-table inheritance. Try something like the following:

    class Gallery(models.Model):
        head_image = models.ImageField(upload_to="gallery")
    
    class Image(models.Model):
        image = models.ImageField(upload_to="gallery")
        gallery = models.ForeignKey(Gallery, related_name='images')
    
    class Tour(Gallery):
        ...
    

    And for the love of all that’s holy, read the Python styleguide. Method names should be in lower case with underscores to avoid namespace clashes with classes.

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

Sidebar

Related Questions

I have a Rails app with some basic models. The website displays data retrieved
I have some models; Vocabularies (tags lists), Labels (tags) and different articles types. These
I have some models witch are using Doctrine nestedset feature. I want to add
Let's say I have some models: User , Post , and Vote . A
I would like to use Markov models for some architecture simulations, but don't have
What are some of the ways you have implemented models in the Zend Framework?
I have a process which iterates through a bunch of ActiveRecord models, does some
I have some model objects I'm using in my Java client application. Later these
Lets say we have some basic AR model. class User < ActiveRecord::Base attr_accessible :firstname,
I have some constants that represent the valid options in one of my model's

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.