Wednesday, October 19, 2011

custom widgets: passing data between widget/field/form/model

i'm subclassing ForeignKey but can't figure out howto access actual
instance (model data).
if i'm doing "class MyField(ForeignKey)", what do i need to override,
which MyField method, where i have access to related instance data (or
None if it doesn't exists)?

digging through the code i've found "self.rel" and "self.related" but
didn't figure out how to get actual model instance or related model
instance.

i've read https://docs.djangoproject.com/en/1.3/howto/custom-model-fields/
and similar docs, tried searching through the source code but the best
thing i've found was id or similar.

is this some kind design decision or am i just missing something obvious?

what i'm actually trying to create is a custom widget (would call it
advanced compared to basic widgets available in django forms/admin)
but i need model instance data in widget.

i've heard theories while asking about this that it's not necessary to
have model instance to create a custom widget but i've found it
impossible to create a generic reusable widget which interacts with
the entire form and available form data (client and server side) and
also with external services (rest/soap api) without access to model
instance.

any tips, links, docs or any constructive comments are appreciated.

Aljosa

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate