Django ModelForm instance with custom queryset for a specific field

后端 未结 3 857
野趣味
野趣味 2020-12-08 14:55

I have a model not unlike the following:

class Bike(models.Model):
    made_at = models.ForeignKey(Factory)
    added_on = models.DateField(auto_add_now=True         


        
3条回答
  •  不知归路
    2020-12-08 14:59

    Nowaday, you should use:

        form.base_fields['alumno_item'].queryset = AlumnoItem.objects.prefetch_related(
            'alumno',
            'alumno__estudiante',
            'alumno__estudiante__profile',
            'item'
        )
    

提交回复
热议问题