I have an inline that displays the contenttype model, so the content_type and object_id fields are displayed. I can hide them using exclude , but I also need to display a drop-down list with all the "Places" and the selected current place based on the content_type and object_id . How can I do it?
Models:
class Criterias(models.Model): name = ... class Places(models.Model): name = ... class PlacesToCriterias(models.Model): content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) object_id = models.PositiveIntegerField() content_object = GenericForeignKey() criteria_group = models.ForeignKey(Criterias) Admin:
class CriteriaPlacesInlineAdmin(admin.TabularInline): model = PlacesToCriterias class CriteriasAdmin(admin.ModelAdmin): inlines = [CriteriaPlacesInlineAdmin] admin.site.register(Criterias, CriteriasAdmin) I can add a form to inline CriteriaPlacesInlineAdmin :
class CriteriaPlacesChoicesFieldForm(forms.ModelForm): places = forms.ModelChoiceField(PlaceTypesGroups.objects.all(), label='place') but how, in this case, pass content_type and object_id to this form to get a drop-down list with all the "Places" and with the selected current location based on the content_type and object_id ?