मैं केवल एक विशेष स्थिरता में टीम से संबंधित खिलाड़ियों को दिखाना चाहता हूं। आम तौर पर जब मैं ऐसा करता हूं, तो यह मुझे डेटाबेस से मेरे सभी खिलाड़ियों को दिखाता है। यहाँ मेरी models.pyformfield_for_foreignkey और इनलाइन व्यवस्थापक
class InningsCard(models.Model):
fixture = models.ForeignKey(Fixture)
team = models.ForeignKey(Team)
runs = models.IntegerField(max_length=6, default=0)
wickets = models.IntegerField(max_length=6, default=0)
overs = models.FloatField(max_length=6, default=0.0)
def __unicode__(self):
return str(self.team)
class BattingDetail(models.Model):
STATUS_CHOICES = (
('no', 'not out'),
('bowled', 'bowled'),
('caught', 'caught'),
('lbw', 'lbw'),
)
innings = models.ForeignKey(InningsCard)
player = models.ForeignKey(Player)
runs = models.IntegerField(max_length=5, default=0)
status = models.CharField(max_length=15, choices=STATUS_CHOICES, default='no')
def __unicode__(self):
return str(self.player)
अब यहाँ है और मेरी admin.py formfield_for_foreignkey शामिल करने के लिए है, लेकिन यह काम नहीं करता।
class BattingInline(admin.TabularInline):
model = BattingDetail
extra = 0
def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
if db_field.name == 'player':
kwargs = Player.objects.filter(team = request.team)
else:
pass
return super(BattingInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
class InningCardAdmin(admin.ModelAdmin):
inlines = [BattingInline]
मैं गलत कहां जा रहा हूं?
// माउस