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).
>>
>> Bob
>>
>>
>>
>>
>
>
>
--
Carlos Perelló Marín
[P+] SERVICIOS PROFESIONALES
http://www.pemas.es
mailto:[email protected] || mailto:[email protected]
Este mensaje y los ficheros anexos son confidenciales. Los mismos
contienen información reservada de la empresa que no puede ser
difundida. Si usted ha recibido este correo por error, tenga la
amabilidad de eliminarlo de su sistema y avisar al remitente mediante
reenvío a su dirección electrónica; no deberá copiar el mensaje ni
divulgar su contenido a ninguna persona.
Su dirección de correo electrónico junto a sus datos personales forman
parte de un fichero titularidad de PEMAS Servicios Profesionales, S.L.
cuya finalidad es la de mantener el contacto con Ud. De acuerdo con la
Ley Orgánica 15/1999, usted puede ejercitar sus derechos de acceso,
rectificación, cancelación y, en su caso, oposición enviando una
solicitud por escrito, acompañada de una fotocopia de su DNI dirigida a
PEMAS Servicios Profesionales, S.L. C/ Santos Justo y Pastor, 72 - 5,
C.P. 46022 de Valencia (España).
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---