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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:05:58+00:00 2026-06-09T13:05:58+00:00

The application I’m writing includes a pipeline for creating events. An Event is proposed

  • 0

The application I’m writing includes a pipeline for creating events. An Event is proposed by one class of users, then approved and edited by administrators. The problem for me is that there is a subclass of Event, ScoredEvent, which the administrators should be able to specify on-the-fly. This adds a ScoredEvent.competition foreign key and overrides the Event.participants to put them through a table that includes an associated score for each participant.

Ideally, a normal user creates an event containing only the name and a short description (easy enough to do by limiting the fields on the non-admin CreateEventForm) then the admins can go back in and fill out the other fields when they are approving the event.

The problem I’m hitting is I don’t know how it would be possible for an administrator to change an Event to a ScoredEvent in the approval form view when they are editing it or how to make that happen. My vision of the page is an edit view with a checkbox labeled “Tie To Competition” that, when checked, would allow the admin to select a competition and then save the event as a ScoredEvent. If that box weren’t checked, the event would continue it’s life as an Event.

Where should this be handled? My gut feeling is that I should do something special in the forms.py or something in the Templates, but I don’t know where I should begin.

class Event(models.Model):                                                       
    """Representation of any community event"""                                  
    name = models.CharField(max_length=50, unique_for_date="start_datetime")     
    slug = models.SlugField(max_length=57) # length +7 for datestamp             
    description = models.TextField()                                             
    location = models.CharField(max_length=100, blank=True)                      
    start_datetime = models.DateTimeField('Start', blank=True)                   
    end_datetime = models.DateTimeField('End', blank=True)                       
    participants = models.ManyToManyField(Participant)                                                                                            

    def save(self, *args, **kwargs):                                             
        if not self.slug:                                                        
            self.slug = slugify(self.name)+'-'+datetime.now().strftime("%d%m%y") 
        super(Event, self).save(*args, **kwargs)                                 

    def __unicode__(self):                                                       
        if self.start_datetime:                                                       
            return "%s (%s)" % (self.name, self.start_datetime.date())           
        else:                                                                    
            return self.name                                                     

class ScoredEvent(Event):                                                        
    """Representation of an event that is tied to a competition"""               
    competition = models.ForeignKey(Competition)                                 
    participants = models.ManyToManyField(Participant, through="ScoredParticipant")

    def is_scored(self):                                                         
        """Returns true if any of the participants has a score, else returns false"""
        for participant in self.participants.objects.all():                              
            if participant.score != 0:                                           
                return False                                                     
        return True                                                              

class ScoredPartcipant(models.Model):                                            
    """Participant and associated score for an event"""                          
    participant = models.ForeignKey(Participant)                                 
    event = models.ForeignKey(ScoredEvent)                                                                                                               
    score = models.IntegerField(default=0)
  • 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-09T13:05:59+00:00Added an answer on June 9, 2026 at 1:05 pm

    Override get_queryset and vary on whether one of the fields is posted:

    def get_queryset(self):
        if self.request.POST.has_key('competition'):
            return ScoredEvent.objects.all()
        else:
            return super(MyView, self).get_queryset()
    

    So, just to explain a little better: you would use your “Tie to Competition” option you mentioned to add a field to the form via Javascript. Then, if the field is sent in the POST, it would switch to using ScoredEvent instead.

    If you want to automatically switch based on what the object currently is, you’d need to override get_object for that. Something along the lines of:

    def get_object(self, queryset=None):
        obj = super(MyView, self).get_object(queryset=queryset)
        try:
            return ScoredEvent.objects.get(pk=obj.pk)
        except ScoredEvent.DoesNotExist:
            return obj
    

    Which basically tries to lookup the object again as if it was a ScoredEvent and returns that version if it finds one, instead of Event.

    You also might need to similarly override get_form_class to ensure that it validates as a ScoredEvent should if it’s a ScoredEvent or is becoming a ScoredEvent:

    from django.forms import models as model_forms
    
    def get_form_class(self):
        if isinstance(self.object, ScoredEvent):
            return model_forms.modelform_factory(ScoredEvent, ScoredEventForm)
        else:
            return super(MyView, self).get_form_class()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Application: WPF Application consisting of a textbox on top and a listbox below Users
My application has one activity which starts two services but does not bind them.
Application : I am working on one mid-large size application which will be used
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
Our application allows users to upload javascript, CSS, and HTML files. We need a
Application level events and processes in Excel are restricted to a single instance of
My application now needs to create and then write files to a temp directory
My application want to upload data to backend. Upload functionality available 2 places. One
My application purpose just simply captures a ISBN number then converts ISBN to a
My application is allowed users to upload jpeg/png files.I must to detect files with

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.