ok, i think i have it sussed out.  my database was doing some freaky
shit as a result of some test data, so what should have been working
was throwing a template error.  anyway, for the sake of continuity of
the thread, here is the way to access the custom fields at the
template level, using carlos' example:

{{ user_data.localcontact.vat_number }}


On Oct 13, 10:56 am, plungerman <[email protected]> wrote:
> hola carlos,
>
> can you explain how you make the vat_number value available at the
> template level for viewing in, for example, the Account info page?  i
> have managed to set up the listeners as you described to add the new
> field to the update account form, but i cannot seem to figure out how
> to make the value available for viewing on the account info page.
>
> saludos,
>
> steve
>
> On Sep 10, 8:29 am, Carlos Perelló Marín <[email protected]> wrote:
>
> > Btw, I'm not attaching my model to the user model, but to the contact model:
>
> > class LocalContact(models.Model):
> >     """Contact model extension to store extra tryton info."""
> >     contact = models.OneToOneField(Contact, verbose_name=_('Base Contact'))
>
> >     vat_number = models.CharField(verbose_name=_('VAT Number'),
> > max_length=30)
>
> > Carlos Perelló Marín escribió:
>
> > > If you want to add just one field, that's a lot of code to write.
>
> > > This is what I did:
>
> > > def tryton_contact_form_postsave(sender, object=None, formdata=None,
> > > form=None,
> > >                                  **kwargs):
>
> > >     if object is None:
> > >         return
>
> > >     try:
> > >         local_contact = LocalContact.objects.get(contact=object)
> > >     except LocalContact.DoesNotExist:
> > >         local_contact = LocalContact(contact=object)
>
> > >     local_contact.vat_number = formdata['vat_number']
> > >     local_contact.save()
>
> > > def tryton_contact_add_form_fields(sender, form=None, **kwargs):
> > >     """Adds some extra fields to the contact form"""
>
> > >     vat_number = ''
> > >     if form._contact:
> > >         if getattr(form._contact, 'localcontact', None):
> > >             vat_number = form._contact.localcontact.vat_number
>
> > >     form.fields['vat_number'] = forms.CharField(
> > >         label='VAT number', required=True, max_length=100,
> > > initial=vat_number)
>
> > > Where LocalContact is where my new field is stored and those functions
> > > are signal handlers. I'm registering them as:
>
> > > form_postsave.connect(tryton_contact_form_postsave, 
> > > sender=ContactInfoForm)
> > > form_init.connect(tryton_contact_add_form_fields, sender=None)
>
> > > Also, I'm overriding two templates to show my new field:
>
> > > templates/contact/update_form.html
> > > templates/contact/view_profile.html
>
> > > Cheers.
>
> > > Bob Waycott escribió:
>
> > >> Ricardo,
>
> > >> I don't know that it is a usual task for Satchmo users, but I guess it
> > >> could be. At the least, it could be a pretty common practice among
> > >> people who are using django-registration.
>
> > >> I would advise against your current solution because you've modified
> > >> Satchmo code & may risk a less smooth upgrade path.
>
> > >> The proper way to do this in my opinion, as with anything else in a
> > >> Django project, would be to make your own extension part of a separate
> > >> app that is included in your Django apps. I'd recommend your own
> > >> forms.py & views.py code that did what you wanted it to do and pass
> > >> things off to the appropriate Satchmo views where necessary.
>
> > >> So, in your forms.py, you would import the Satchmo form & extend it. In
> > >> your views.py, you would do whatever extra work you want to do with your
> > >> extended form, calling out to the satchmo view where needed and likely
> > >> returning that view's result after finishing your extra processing. In
> > >> your urls.py, you would ensure that the url for registration goes to
> > >> your custom view. Finally, in the template, you would modify accordingly
> > >> to include your extra field(s).
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Satchmo users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/satchmo-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to