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

  • Home
  • SEARCH
  • 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 8298193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:40:54+00:00 2026-06-08T15:40:54+00:00

I have a form in my website, which is the same for three tables

  • 0

I have a form in my website, which is the same for three tables (Homework, Class, Random)
So basically I want to make a ChoiceField on the top of the form, to let user choose where to upload file.

I was thinking, because these tables have common abstract class, may be I can choose it from there somehow. But can not figure out how.

Or may be there is much better solution for this.

just in case this is my code:

#models.py
class FileDescription(models.Model):

    class Meta:
        abstract = True;
        ordering = ['file_creation_time']

    subject = models.ForeignKey('Subjects', null=True, blank=True, primary_key=True)
    subject_name = models.CharField(max_length=100)
    file_uploaded_by = models.CharField(max_length=100)
    file_name = models.CharField(max_length=100)
    file_description = models.TextField()
    file_creation_time = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
        return u'%s' % (self.file_name)

#template
<ul id="tabs">
        <li><a href="#homework">Homework</a></li>
        <li><a href="#class-papers">Class Papers</a></li>
        <li><a href="#random-papers">Random Papers</a></li>
    </ul>

    <div id="homework" class="tab-section">
        <h2>Homework</h2>
        <p>This section contains Homework</p>

            {% if homework_files %}
                <ul>
                    {% for file in homework_files %}
                        <li>{{ file.file_name }}
                    {% endfor %}
                </ul>
            {% endif %}
    </div>

#forms.py
class Homework_Content_Form(forms.ModelForm):
    class Meta:
        model=Homework_Content
        exclude=('subject', 
                 'subject_name',
                 'file_creation_time',
                 'file_uploaded_by',
                 )
  • 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-06-08T15:40:56+00:00Added an answer on June 8, 2026 at 3:40 pm

    Method 1: Separate Forms

    class GenericContentForm(forms.ModelForm):
         class Meta:
             exclude = ('subject', 'subject_name', 'file_creation_time', 'file_uploaded_by')
    
         TYPE_CHOICES = (
             ('homework', 'Homework'),
             ('class', 'Class Paper'),
             ('random', 'Random Paper'),
         )
    
         type = forms.ChoiceField(choices=TYPE_CHOICES)
    
    class HomeworkForm(GenericContentForm):
         class Meta(GenericContentForm.Meta):
             model = Homework
    
    class ClassPaperForm(GenericContentForm):
         class Meta(GenericContentForm.Meta):
             model = ClassPaper
    
    class RandomPaperForm(GenericContentForm):
         class Meta(GenericContentForm.Meta):
             model = RandomPaper
    

    Then in your view you just pick one to start with, and when you have the POST data, you can instantiate a different one instead:

    def my_view(request):
        if request.method == 'POST':
            type = request.POST.get('type')
            if type == 'homework':
                form = HomeworkForm(request.POST)
            elif type == 'class':
                form = ClassPaperForm(request.POST)
            elif type == 'random':
                form = RandomPaperForm(request.POST)
    
        else:
            form = HomeworkForm()
    
        ...
    

    Method 2: Use Proxy Models

    Since these three models all share the same data, having three separate tables is redundant. Instead of FileDescription being abstract, make it just a normal standard model, and add a field to it for type, with choices of “Homework”, “Class Paper” and “Random Paper”. Then create proxy models for each:

    class HomeworkManager(models.Manager):
        def get_query_set(self, *args, **kwargs):
            qs = super(HomeworkManager, self).get_query_set(*args, **kwargs)
            return qs.filter(type='homework')
    
    class Homework(FileDescription):
        class Meta:
            proxy = True
    
        objects = HomeworkManager()
    
        def save(self, *args, **kwargs):
            self.type = 'homework'
            super(Homework, self).save(*args, **kwargs)
    

    Then, you just need one form for FileDescription and when the user’s choice for the “type” will be saved. You can then access anything set as type “homework” with the standard Homework.objects.all().

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

Sidebar

Related Questions

I have a database which has form authentication tables for an website [let say
On my website, I have a button which when clicked displays a feedback form
I have a form on my website that does the login. To make the
I have a live rails website and I want to have a form with
I have a website, and in the Contact section I have a form which
Currently on my website I have a form in which once it is submitted,
I have a website form that collects url of users to store in a
I have a form on my website that takes input from a text area
You have to have a form on your website for people to send an
I have a login form for my website. This login form have two text

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.