2010-12-06 13 views
0

IPDB Debug speichern Rückkehr:Django: Modelform auf Objekt einer anderen Klasse

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']}> 

Ich spare eine IndividualSiteHomeForm, nachdem es verbindliche Daten zu veröffentlichen. Warum gibt es ein IndividualProfile-Objekt zurück?

Zum Vergleich: 1> Model

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') 

Vielen Dank für Ihre Zeit.

EDIT: var Um zu bestätigen, ist in der Tat 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> 

Antwort

0

Ich glaube nicht, dass eine Instanz von IndividualProfile zurückkehrt. Ich denke, es gibt eine Instanz von IndividualSite, wie Sie erwarten, aber wenn Sie das aus der Shell replizieren, verwendet es die __unicode__ Methode von IndividualSite - die den Wert des ForeignKey zurückgibt, das ein IndividualProfile ist.

+0

Ich bin davon überzeugt, es ist IndividualProfile Objekt ... bitte sehen Sie die EDIT. – trappedIntoCode

Verwandte Themen