2

This is how I've defined my models:

class Technology(models.Model):
    title = models.CharField(max_length=10)

    class Meta:
        verbose_name_plural = 'Technologies'

    def __str__(self):
        return self.title


class Project(models.Model):
    title = models.CharField(max_length=100)
    description = HTMLField()
    technology = models.ManyToManyField(Technology, related_name='projects')
    image = models.ImageField(upload_to='projects/')

    def __str__(self):
        return self.title

And this is how I've defined the models in admin.py:

class TechnologyInline(admin.StackedInline):
    model = Project.technology.through


@admin.register(Technology)
class TechnologyAdmin(admin.ModelAdmin):
    pass


@admin.register(Project)
class ProjectAdmin(admin.ModelAdmin):
    inlines = [
        TechnologyInline,
    ]
    exclude = [
        'technology',
    ]

And this is the result: enter image description here

This is exactly what I need, but it's very ugly. Is it possible to customize the strings such as "Project-technology relationship: #1" and others?

Omid Shojaee
  • 333
  • 1
  • 4
  • 20
  • What if you set `verbose_name='technology' and `verbose_name_plural='technologies'` for your `TechnologyInline`? – Willem Van Onsem Jun 29 '21 at 15:10
  • Does this answer your question? [How to set another Inline title in Django Admin?](https://stackoverflow.com/questions/4807479/how-to-set-another-inline-title-in-django-admin) – Iain Shelvington Jun 29 '21 at 15:11
  • Thanks. I've already set the verbose names. I'm asking about other strings such as "Project-technology relationship #1, #2, #3,...". I want to set an entirely different string for them. – Omid Shojaee Jun 29 '21 at 16:04
  • I would also wish to don't show empty relations. A plus button to add them onm demand would be enough. – EinEsellesEniE Jul 06 '22 at 14:23

0 Answers0