我想基于父级连击的选择来填充从属连击。我的代码如下:
class Species(models.Model):
name = models.CharField(max_length=120, blank=False, null=False)
description = models.TextField(max_length=300, blank=False, null=False)
class SpeciesDetail(models.Model):
species = models.ForeignKey(Species, on_delete=models.CASCADE)
picture = models.ImageField(upload_to='pics')
gender = models.CharField(max_length=1)
health = models.CharField(max_length=120)
class Pair(models.Model):
species = models.ForeignKey(Species, on_delete=models.CASCADE)
male = models.ForeignKey(SpeciesDetail, on_delete=models.CASCADE, related_name='male_set')
female = models.ForeignKey(SpeciesDetail, on_delete=models.CASCADE, related_name='female_set')
从django.contrib导入管理员
来自.models import物种,SpeciesDetail,对,
class PairAdmin(admin.ModelAdmin):
list_display = ('species', 'male', 'female',)
search_fields = ('male', 'female', )
filter_horizontal = ()
list_filter = ()
ordering = ['species']
fieldsets = ()
答案是DAL(Django Autocomplete Light。