S
S
Stanislav2020-11-03 15:15:28
Django
Stanislav, 2020-11-03 15:15:28

How to display the ForeignKey fields of the second level model in the Django admin?

How to make image field output in one line before TwoInline fields?
models.py

class One(models.Model):
    image = models.ImageField()

class Two(models.Model):
    one = models.ForeignKey(One,on_delete=models.CASCADE)
    three = models.ForeignKey(Three,on_delete=models.CASCADE)

class Three(models.Model):
    pass

admin.py
class TwoInline(admin.TabularInline):
    model = Two

@admin.register(Three)
class ThreeAdmin(admin.ModelAdmin):
    inlines = [TwoInline]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question