19

Basically I am trying to recreate a fields in this model that is similar to django user authenticate system, for this I try using many-to-many fields but it ended up like this.

enter image description here

I am trying to have another field that can show what exist and another field for I have chosen similar to django admin, which looks like this.

enter image description here

This is my code

class Category(models.Model):
    name = models.CharField(max_length=128, unique=True)

class BlogPage(models.Model):
    category = models.ManyToManyField(Category)
    title = models.CharField(max_length=128)
    preview = models.TextField(max_length=256)
    content = models.TextField()
karthikr
  • 97,368
  • 26
  • 197
  • 188
Nameless
  • 479
  • 1
  • 6
  • 16

2 Answers2

35

I believe what you want is a filter_horizontal widget used in the Admin template. This should help: Django Admin ManyToManyField

Community
  • 1
  • 1
souldeux
  • 3,615
  • 3
  • 23
  • 35
1

currently i am able to display many to many fields is admin panel

models.py

class Abc(models.Model):
    course = models.ManyToManyField(Course, blank=True)

admin.py

class AbcsAdmin(admin.ModelAdmin):
    """
    Admin panel management for Alumni
    """
list_display = ["id","get_course"]

def get_course(self,obj):
    return [course.name for course in obj.course.all()]
Neeraj Kumar
  • 133
  • 1
  • 4