您好,登錄后才能下訂單哦!
models.py
class xm(models.Model): xmID=models.AutoField(primary_key=True) xmTitle=models.CharField('項目標題',max_length=50) xmDate=models.DateField('時間',auto_now_add=True) class Meta: db_table="std_web_xm" verbose_name="項目概況" verbose_name_plural=verbose_name def __unicode__(self): return self.title def __str__(self): #強制轉換為int類型 return str(self.xmID)#為了使在xadmin中成功顯示為xmID class xmProgress(models.Model): xmProgress_ID=models.AutoField(primary_key=True) xmProgress = models.CharField('項目進展', max_length=50, blank=True) xmDesc = models.CharField('詳情', max_length=50, blank=True) #關聯主鍵xmID ,級聯刪除 cid=models.ForeignKey("xm",on_delete=models.CASCADE) xmProgress_Date=models.DateField('更新時間',auto_now_add=True) class Meta: db_table="std_web_xmProgress" verbose_name="項目詳情" verbose_name_plural=verbose_name def __unicode__(self): return self.title
注冊到adminx.py中
class XmAdmin(object): list_display = ['xmTitle','xmDate'] #style_fields = {"xmContent": "ueditor"} class XmProgressAdmin(object): list_display=['cid','xmProgress','xmProgress_Date','xmDesc'] xadmin.site.register(xm,XmAdmin) xadmin.site.register(xmProgress,XmProgressAdmin)
views.py
def xm_detail(request,xmID): xm_detail=xm.objects.get(pk=xmID) xmProgress_detail=xmProgress.objects.filter(cid=xm_detail) return render(request,'xmgk/xmgk_detail.html',{'xmProgress_detail':xmProgress_detail,'xm_detail':xm_detail})
前端代碼
{% for line in xmProgress_detail %} <tr> <td>{{ line.xmProgress_Date|date:"Y-m-d" }}</td> <td>{{ line.xmProgress }}</td> <td>{{ line.xmDesc }}</td> </tr> {% endfor %}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。