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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:31:58+00:00 2026-06-13T12:31:58+00:00

I have a main Event class, and four event types. Each of them is

  • 0

I have a main Event class, and four event types. Each of them is a subclass of (at least) Event. On an event’s detail page, I am adding a link back to the admin interface for a given event to save the time of searching in the admin. Unfortunately, regardless of child class, the events are selected from the parent Event class. My solution to this problem was to duck type, which I find to be absolutely awful in this instance. I am hoping there is a more elegant and easy-to-maintain solution to my problem.

Model:

class Event(models.Model):
    ...

class ListedEvent(Event):
    ....

class RSVPEvent(Event):
    ....

class TicketedEvent(Event):
    ....

class TicketedConcert(TicketedEvent):
    ....

To see event details, the URL passes a venue slug and event name slug. This is enough info to isolate a single event from the parent Event model across all the child events. It also lets me keep the event type out of the URL, making them simpler and more friendly.

@render_to('events/event_details.html')
def event_details(request, venue, slug):
    """
    Detail view of an event.
    """
    try:
        event = Event.objects.select_related(
            'listedevent',
            'rsvpevent',
            'ticketedevent',
            'ticketedconcert',
            'venue',
            'sites',
            'dj',
        ).get(
            slug=slug,
            venue__slug=venue,
        )
    except Event.DoesNotExist:
        raise Http404

    return {'event': event}

Before I went back and realized that I was using the parent Event model, this solution was much more elegant and worked fine in the shell assuming I select an event from its actual model (property of parent class Event):

@property
def admin_link(self):
    et = self.__class__.__name__.lower()
    # ALWAYS: et == 'event', reverse() fails, returns ''
    return reverse('admin:events_%s_change' % et, args=(self.id,))

My current solution (property of parent class Event):

@property
def admin_link(self):
    duck = None

    try:
        duck = self.ticketedevent.ticketedconcert.artist_name
        return reverse(
            'admin:events_ticketedconcert_change',
            args=(self.id,)
        )
    except:
        pass

    try:
        duck = self.ticketedevent.max_tickets
        return reverse(
            'admin:events_ticketedevent_change',
            args=(self.id,)
        )
    except:
        pass

    try:
        duck = self.rsvpevent.total_rsvp
        return reverse(
            'admin:events_rsvpevent_change',
            args=(self.id,)
        )
    except:
        pass

    try:
        duck = self.listedevent.name
        return reverse(
            'admin:events_listedevent_change',
            args=(self.id,)
        )
    except:
        pass

There has to be a simpler, more easy-to-maintain method of finding out which type of event I’m looking at. Any ideas?

  • 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-13T12:31:59+00:00Added an answer on June 13, 2026 at 12:31 pm

    This is a common issue and still seems to be one of Django’s uglier ducklings.

    You could at least rearrange for 2 cents of DRY gain:

    from django.core.exceptions import ObjectDoesNotExist
    
    @property
    def event_type(self):
         for et in ('ticketedevent', 'rsvpevent', 'sillyhatsonlyevent', ...):
             try:
                 getattr(self, et)
                 return et
             except ObjectDoesNotExist:
                 pass
    
    @property
    def admin_link(self):
        return reverse('admin:events_%s_change' % self.event_type, args=(self.id,))
    

    If you really want to be fancy, you could use Event.__subclasses__ and generate the list of event types.

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

Sidebar

Related Questions

I have a question about the 'Event Dispatch Thread'. I have a Main class
I have declared an event in my UserControl class Main: public static readonly RoutedEvent
I have a main application frame ( MainFrame class ). On actionperformed event of
I have a local thread that is started on button-click event from the main
i have main activity in which i have Four menus. and i have one
I have main.cpp (including main function) and func1.cpp, and I want to link these
I have 2 classes within same package. Both classes have main method in them.
I have two classes orchestrated by a main class and I would like to
I have a main class Gui that handles my GUI and calls a few
I have three classes, one main class, one GUI class which uses awt+swing to

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.