开发者

Including many-to-many from another model in field in django admin interface

开发者 https://www.devze.com 2023-02-22 03:26 出处:网络
Greetings, I\'m sure there is a simple solution to what I\'m trying to do but unfortunately I wasn\'t able to find it in the documentation.

Greetings, I'm sure there is a simple solution to what I'm trying to do but unfortunately I wasn't able to find it in the documentation.

I have the following model (simplified version shown):

models.py:

class Student(models.Model):
  student_id = models.IntegerField(primary_key=True, unique=True,
      db_index=True, max_length=9)
  first_name = models.CharField(max_length=50)
  last_name  = models.CharField(max_length=50)

  def __unicode__(self):
    return u"%s %s" % (self.first_name, self.last_name)

class Course(models.Model):
  course_id = models.AutoField(primary_key=True, unique=True,
                              db_index=True, max_length=4)
  title = models.CharField(max_length=50)
  dept = models.CharField(max_length=6)
  number = models.IntegerField(max_length=5)
  student_id = models.ManyToManyField(Student, blank=True)

  def __unicode__(self):
    return u"%s %s" % (self.dept, self.number)

What I wanted was to be able to add students to multiple classes in the admin interface similar to the way that I can add students in the cla开发者_如何转开发sses admin interface. If there is yet another way that seems more beneficial I would be interested in that as well.

Thanks in advance for any help!


You can use the inlines in your related model, or this blog post might be of some help.

0

精彩评论

暂无评论...
验证码 换一张
取 消