Django admin site automatically populates a combo box based on input

Hi, I have to follow the following class Match model (models.Model):

    Team_one = models.ForeignKey('Team', related_name='Team_one') 
    Team_two = models.ForeignKey('Team', related_name='Team_two') 
    Stadium = models.CharField(max_length=255, blank=True)
    Start_time = models.DateTimeField(auto_now_add=False, auto_now=False, blank=True, null=True)
    Rafree = models.CharField(max_length=255, blank=True)
    Judge = models.CharField(max_length=255, blank=True)
    Winner = models.ForeignKey('Team', related_name='winner', blank=True)    
    updated = models.DateTimeField('update date', auto_now=True )
    created = models.DateTimeField('creation date', auto_now_add=True )
    def save(self, force_insert=False, force_update=False):
      pass

   @models.permalink
   def get_absolute_url(self):
       return ('view_or_url_name')
class MatchAdmin(admin.ModelAdmin):
   list_display = ('Team_one','Team_two', 'Winner')
   search_fields = ['Team_one','Team_tow']

 admin.site.register(Match, MatchAdmin)

I wondered if their way is to fill in the list of winners as soon as the first team and the second team is selected on the admin site?

+3
source share
2 answers

There is no real easy way to do this with the django admin. It is possible, but it will require you to replace the admin form and subclass the widget using javascript, which copies the command into the field. Way more effort than it costs.

, winner_team loser_team

: http://www.python.org/dev/peps/pep-0008/

+1

Source: https://habr.com/ru/post/1736757/


All Articles