0
我遇到了問題,我無法找到解決方案。我有下一個類Django表單,字段和模型
#models.py
from django import models
class Suggest(models.Model):
user = models.ForeignKey(User, null= True, blank=True)
article = models.ForeignKey(Article)
name = models.ChardField(max_length=100)
types = (('suggest','Sugest'),('note','Note'),('complain','Complain'))
type = models.CharField(max_length=80, choices = types, default='suggest')
content = models.TextField()
dataX = models.CharField(max_length=200) #example
#forms.py
from django import form
from .models import Suggest
class SuggestForm(form.ModelForm): #File forms.py,
class Meta:
fields = ('name','type','content')
我已經有一些更完整的,但這個代碼足以解釋我的疑惑。我需要使用兩個參數(article,request.user)創建此表單,文章必須通過隱藏字段保持關聯。 當請求用戶登錄時,名字必須等於(request.user.first_name +「」+ request.user.last_name),並將登錄用戶的ID保存在用戶名中。用戶登錄時必須顯示內容。
我的第二個疑問是我如何完成例如DATAX如果該字段是不是在形式