2010-12-06 6 views
0

ipdbデバッグ:ジャンゴ:別のクラスのオブジェクトを返す保存上のModelForm

ipdb> form_class 
<class 'myproject.apps.usersites.forms.IndividualSiteHomeForm'> 
ipdb> form = form_class(request.POST) 
ipdb> form 
<myproject.apps.usersites.forms.IndividualSiteHomeForm object at 0x021A81F0> 
ipdb> var = form.save(commit= False) 
ipdb> var 
<IndividualProfile: user1> 
ipdb> request.POST 
<QueryDict: {u'csrfmiddlewaretoken': [u'208ff2a5a78bd5c2ba9452b365b59b6d'], u'ho 
me_content': [u'Some contents']}> 

は、私がデータをPOSTするためにそれを結合した後IndividualSiteHomeFormを保存しています。 なぜIndividualProfileオブジェクトを返すのですか?

参考: 1>モデルのお時間を

class IndividualSite(SiteBase): 
individual = models.ForeignKey(IndividualProfile, unique=True, verbose_name = _("Professional")) 
logo = models.ImageField(upload_to="sites/logos/",verbose_name=_("logo"))  
home_content = models.TextField(_("Home contents"), null=True, blank=False, 
           help_text = "This text will appear on your web site home. Do not use HTML here.")  

def __unicode__(self): 
    return self.individual.name 

2>のModelForm

class IndividualSiteHomeForm(ModelForm): 
class Meta: 
    model = IndividualSite 
    exclude = ('individual','user','logo') 

感謝。

EDIT:VARを確認するためにはIndividualProfile確かです:

ipdb> var 
<IndividualProfile: user1> 
ipdb> var.home_content 
*** AttributeError: 'IndividualProfile' object has no attribute 'home_content' 
ipdb> var.__class__ 
<class 'profiles.models.IndividualProfile'> 
ipdb> 

答えて

0

私はそれがIndividualProfileのインスタンスを返しているとは思いません。私は期待通りにIndividualSiteのインスタンスを返すと思いますが、シェルからそれをreprするときは、IndividualSiteの__unicode__メソッドを使用します。これはIndividualProfileであるForeignKeyの値を返します。

+0

私はそれがIndividualProfileオブジェクトです。それはEDITを見てください。 – trappedIntoCode

関連する問題