Monday, January 31, 2011

Issue with Foriegnkey in django

i AM trying to create a from which is linked with foriegnkey.

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

Please help me on this ...........

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment