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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:44:33+00:00 2026-05-28T07:44:33+00:00

I have a Competition model which has a corresponding CompetitionEntry model. I’d like to

  • 0

I have a Competition model which has a corresponding CompetitionEntry model. I’d like to show the number of entries for each competition in the admin view.

Here’s the model definition:

class Competition(models.Model):

    def __unicode__(self):
        return self.competition_name

    competition_name = models.CharField(max_length=100)
    competition_text = models.TextField()
    active = models.BooleanField('Is this competition active?', blank=True)
    date_posted = models.DateTimeField(auto_now_add=True)

class CompetitionEntry(models.Model):

    def __unicode__(self):
        return self.competition.competition_name

    competition = models.ForeignKey(Competition)
    user = models.ForeignKey(User)
    date_entered = models.DateTimeField(auto_now_add=True)
    is_winner = models.BooleanField('Is this entry the winner?', blank=True)

My Django skills are a little rusty, but there should be a fairly simple way to add this to the admin, right? Any pointers? I can’t quite work out how the Competition class can ‘talk’ to the CompetitionEntry class since the relationship is defined inside CompetitionEntry, but I want to show the entries inside Competition.

  • 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-28T07:44:33+00:00Added an answer on May 28, 2026 at 7:44 am

    You can refer to python functions in a ModelAdmin by adding it to the fieldsets or list_display and readonly_fields attributes.

    You can ‘talk’ to a reverse relationship via the reverse related managers dynamically added to each class that a foreign key points to which is, by default, lowercasemodelname_set and behaves exactly like your default objects manager.

    class MyAdmin(admin.ModelAdmin):
        list_display = ('_competition_count',)
        readonly_fields = ('_competition_count',)
    
        fieldsets = (
            (None, {'fields': (
                '_competition_count',
            )})
        )
    
        def _competition_count(self, obj):
            return obj.competitionentry_set.count()
        _competition_count.short_description = "Competition Count"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Person entity which has composition with Location Entity @ManyToOne(fetch = FetchType.EAGER, cascade
I have this function, which loads a select from a database. function Competition() {
I have the following models & mappings (code snippets further below). One Competition has
I have three models. Call them A, B, and C. Model A has _post_put_hook
I've got a simple Django photography competition app that has three simple model definitions:
I have the following hierarchy of assemblies: MyRoot MyRoot.General MyRoot.General.Model MyRoot.General.MyApp Each assembly should
I was looking at what the guys in the Mario AI Competition have been
I've been practicing for an upcoming programming competition and I have stumbled across a
I have an application which I am developing using WPF\Prism\MVVM. All is going well
I have a CI Model set up with this function and ActiveRecord: function get_open_competitions()

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.