I have inline, which shows data of contenttype
model, so instead of real objects, I see content_type
and object_id
fields. I can exclude
these fields - this is not a problem, but also I want to get real object as selected
with another Places
in a dropdown list. Could anyone tell me, how can I do this?
Model:
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 to CriteriaPlacesInlineAdmin
a form
, something like:
class CriteriaPlacesChoicesFieldForm(forms.ModelForm):
places = forms.ModelChoiceField(PlaceTypesGroups.objects.all(), label='place')
but how can I pass\add object_id
to this form\query in order to get 'selected' place in the dropdown list?