As stated in the title how does manytomanyfield
with through
appear in the admin site?
class SchoolClass(models.Model):
id = models.AutoField(primary_key = True)
class_name = models.TextField()
level = models.IntegerField()
taught_by = models.ManyToManyField(User,related_name="teacher_teaching",through='TeachSubject')
attended_by = models.ManyToManyField(User,related_name='student_attending')
def __unicode__(self):
return self.class_name
class Meta:
db_table = 'classes'
class TeachSubject(models.Model):
teacher = models.ForeignKey(User)
class_id = models.ForeignKey(SchoolClass)
subject = models.ForeignKey(Subject)
In the admin site, for the model SchoolClass
, I have a field for attending students, but not the teachers.
Django Admin's "change list" is the page that lists all objects of a given model. Now, all your articles should have a different name, and more explicit than "Article object".
The Django admin application can use your models to automatically build a site area that you can use to create, view, update, and delete records. This can save you a lot of time during development, making it very easy to test your models and get a feel for whether you have the right data.
You should use InlineModelAdmin
. Docs.
class TeachSubjectInline(admin.TabularInline): model = TeachSubject extra = 2 # how many rows to show class SchoolClassAdmin(admin.ModelAdmin): inlines = (TeachSubjectInline,) admin.site.register(SchoolClass, SchoolClassAdmin)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With