文章出處
1.查詢框、連接設置,列表顯示、詳情頁字段顯示等,django的查詢框有全文檢索的功能,即設置多個查詢項都在一個查詢框上實現
例如:
在admin.py里在上
class MsgAdmin(admin.ModelAdmin): list_display = ('title','content','user','type','ctime') search_fields = ('title','content','user__nickname','user__city')# 設置搜索框范圍 ,如果有外鍵,要注明外鍵的哪個字段,雙下劃線 # list_display_links = ('title') # 設置頁面上哪個字段可單擊進入詳細頁面 # fields = ('title'', 'content') # 設置添加/修改詳細信息時,哪些字段顯示
2.主鍵自增
如果是int類型的,在數據庫里把表的主鍵設置成自增就,然后model設置成 id = models.autofield(primary_key=True)就可以了
例如:
class User(models.Model): id = models.autofield(primary_key=True) name = models.CharField(unique=True, max_length=45) age = models.CharField(unique=True, max_length=45) class Meta: managed = False db_table = 'user'
看文倉www.92to.com網友整理上傳,為您提供最全的知識大全,期待您的分享,轉載請注明出處。
歡迎轉載:http://www.kanwencang.com/bangong/20161228/79116.html
文章列表
全站熱搜