0
ForeignKey와 연결된 양식을 만들려고합니다. 내가 질문을받을 경우Django의 ForeignKey 문제
Model.py
enter code here
model.py
class CreateD(models.Model):
id=models.IntegerField(primary_key=True)
db = models.CharField(max_length=50, blank=True)
iss = models.CharField(max_length=100, blank=True)
status = models.CharField(max_length=2, blank=True ,default='A')
class Meta:
db_table = u'add_d'
def __unicode__(self):
return u'%s %s' % (self.db,self.iss)
class Assignment(models.Model):
id = models.IntegerField(primary_key=True)
assign_to = models.CharField(max_length=50, blank=True)
db_name = models.ForeignKey(CreateDb,related_name='set__dbname')
issue_type = models.ForeignKey(CreateDb,related_name='set_issuetype')
date = models.DateTimeField(null=True, blank=True)
class Meta:
db_table = u'assignment'
def __unicode__(self):
return u'%s %s' % (self.db_name,self.issue_type)
form.py
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
exclude = ('id','date','assign_to')
assign.html
{{forms.as_p}}
Data in the sql :
id db iss
1 A AB
2 B BA
Output genrated from html page is
db_name : A AB (choice field)
B BA
issue_type : A AB (choice field)
B BA
Actually i Need a output like below in html:
db_name : A (choice field)
B
issue_type : AB (choice field)
BA
바로 그들이 통해 생성 기본적으로 선택 상자의 레이블을 변경하려면 ...........이에
잘 모르겠지만 정의한 __unicode__와 관련이 있습니까? 대신 CreateD가 self.db를 반환하도록 def를 변경하면 작동합니까? – PhoebeB
작동하지 않는 것이 무엇인지 설명하면 도움이됩니다. –
db_name 밑에 만 db를 가져오고 issue_type.but 밑에 iss하고 싶습니다. 문제는 선택 필드에 있습니다. 선택 필드에 대해 db와 iss를 얻고 있습니다. 유니 코드는 db를 반환하고 iss.if는 iss 만 제거합니다. – sush