Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango Multiple GenericRelation related_name in admin
    primarykey
    data
    text
    <p>I'm tring to create a generic foreign key and reuse it multiple time inside the same model</p> <p>The problem is that when I load the admin interface I got the 2 Inline fields that display the same data.</p> <p>I tried to use an fk_name passing the related_name defined in the model but without luck</p> <p>Here is the code any help is appreciate</p> <h1>model.py:</h1> <pre><code>class TranslatedCharField(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() class Meta: unique_together = ('object_id', 'lang') lang = models.CharField(max_length=255, choices=LANGUAGES) text = models.CharField(max_length=255) class Evento(models.Model): slug = generic.GenericRelation(TranslatedCharField, related_name="slug") titolo = generic.GenericRelation(TranslatedCharField, related_name="title") </code></pre> <h1>admin.py:</h1> <pre><code>class TranslatedSlugInline(generic.GenericTabularInline): extra = 0 model = TranslatedCharField verbose_name = "Slug" verbose_name_plural = "Slug" class TranslatedTitoloInline(generic.GenericTabularInline): extra = 1 model = TranslatedCharField verbose_name = "Titolo" verbose_name_plural = "Titolo" class EventoAdmin(admin.ModelAdmin): inlines = [ TranslatedSlugInline, TranslatedTitoloInline, ] admin.site.register(Evento, EventoAdmin) </code></pre> <p>this is the result: <img src="https://i.stack.imgur.com/yCfNl.jpg" alt="enter image description here"></p> <p>as you can see the list of TranslatedCharField is duplicated for the 2 relations </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload