Help is needed. There are two models related by ForeignKey

class Properties(models.Model): prop_name = models.CharField(max_length=200, default='') def __unicode__(self): return self.prop_name class Meta: verbose_name = 'Свойство' verbose_name_plural = 'Cвойства' class Value_properties(models.Model): prop_value = models.CharField(max_length=200, default='') prop_goods_properties = models.ForeignKey(Properties, related_name='prop_val') def __unicode__(self): return self.prop_value class Meta: verbose_name = 'Значение свойства' verbose_name_plural = 'Значения свойств' 

There is a third model to which these two are bound by a ForeignKey. How in the admin panel of this model, with which are these two models related, to make a dynamic select based on the second model?

I tried to do this:

 def get_formset(self, request, obj=None, **kwargs): formset = super(Properties_goodInline, self).get_formset(request, obj, **kwargs) q = Properties.objects.all().values_list('id', 'prop_name').distinct() qq = q.values_list('id', 'prop_val__prop_value') formset.form.base_fields['properties'].choices = q formset.form.base_fields['properties_value'].choices = qq return formset 

Separately, there are two selects, but how to connect them. In the second select all values ​​are mixed. For example, it would be possible using Javascript to sort and display them by the selected first value, but how to push the third parameter in qq, for example:

 qq = q.values_list('prop_val', 'id', 'prop_val__prop_value') 

Which will connect them with the first. In this case ***. Choices do not work, because it takes values ​​of the form ('param1', 'param2'). Who can tell, help.

    0