本文介绍了使用Django中的另一个关系表联接两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在管理面板中的list_display遇到问题。

I am having a problem with list_display in admin panel.

class Categories(models.Model):
      cat_id = models.IntegerField(primary_key=True)
      cat_name = models.CharField(_('category name'), max_length=50)

      def __unicode__(self):
          return self.cat_name

class Stories(models.Model):
      story_id = models.IntegerField(primary_key=True)
      story_title = models.CharField(max_length=500)
      story_desc = models.TextField()
      cover_image = models.CharField(max_length=500)
      date_of_creation = models.DateTimeField(auto_now_add=True)
      date_of_publish = models.DateTimeField(auto_now=True)

      def __unicode__(self):
           return self.story_title

class Relation(models.Model):
      tbl_id = models.IntegerField(primary_key=True)
      story_id = models.ForeignKey(Stories)
      cat_id = models.ForeignKey(Categories)

我想使用MySQL中的关系表连接两个表,故事和类别。但是我不希望在关系表中有更多列。

I want to connect two tables, Stories and categories using Relation table in mysql. But i dont want any more columns in Relation table.

此外,我想在管理面板中列出-

Also, I want to list in admin panel-

class StoryAdmin(admin.ModelAdmin):
     list_display = (story_title, story_desc, date_of_creation, cat_name)

admin.site.register(Relation, StoryAdmin)


推荐答案

您看过吗:

,并且:

django: how does manytomanyfield with through appear in admin?

这篇关于使用Django中的另一个关系表联接两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!