hi i have to following model class Match(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_t开发者_运维问答wo', 'Winner')
search_fields = ['Team_one','Team_tow']
admin.site.register(Match, MatchAdmin)
i was wondering is their a way to populated the winner combo box once the team one and team two is selected in admin site ?
Theres no real easy way to do that with the django admin. It's possible, but it would require you to replace the admin form, and subclass the widget with some javascript that copys the Team into the box. Way more effort than it's worth.
If I were you, I'd just have winner_team and loser_team fields
also read this: http://www.python.org/dev/peps/pep-0008/
You need django-smart-selects.
精彩评论