T
T
TitanFighter2016-10-13 19:48:35
Django
TitanFighter, 2016-10-13 19:48:35

How to get data in the admin panel through feedback when using GenericTabularInline?

I can add "criteria" to some "place". How to add "places" to some "criteria"?
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 - Locations:
class PlaceCriteriasInlineAdmin(GenericTabularInline):
    model = PlacesToCriterias

class PlacesAdmin(admin.ModelAdmin):
    inlines = [PlaceCriteriasInlineAdmin]

admin.site.register(Places, PlacesAdmin)

In this case, on the "Places" edit page, I can add "Criteria".
Admin - Criteria:
class CriteriaPlacesInlineAdmin(GenericTabularInline):
    model = PlacesToCriterias

class CriteriasAdmin(admin.ModelAdmin):
    inlines = [CriteriaPlacesInlineAdmin]

admin.site.register(Criterias, CriteriasAdmin)

In this case, on the "Criteria" edit page, I can't add "Places". Instead of a possible list of places, I see a list of criteria.
How to get a list of places on a criteria page?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TitanFighter, 2016-10-14
@TitanFighter

Everything turned out to be very simple - it was necessary to use admin.TabularInline instead of GenericTabularInline

class CriteriaPlacesInlineAdmin(admin.TabularInline):
    model = PlacesToCriterias

class CriteriasAdmin(admin.ModelAdmin):
    inlines = [CriteriaPlacesInlineAdmin]

admin.site.register(Criterias, CriteriasAdmin)

Z
zelsky, 2016-10-13
@zelsky

ManyToManyField ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question