This assumes you made a form with something like:
f = MyForm(instance = someInstance)
On the command-line, try using:
python manage.py shell
Then import your form module and use the dir() command to look around at
what's available.)
hth,
\d
So:
If you are doing something like this:
class SomeWidget( forms.TextInput ):
def __init__(self,attrs=None, PASSANYTHINGHERE=whatever ):
self.whatever = whatever # Helpful stuff
super(fklookupwidget,self).__init__(attrs)
def render(self, name, value, attrs=None):
#value is the field you assign this widget to.
#So, if it's an id or pk, you have it now.
#You also have self.whatever to work with.
hth,
\d
The way Django does this is fairly normal design practice. Normal OO
implementation practice is the hierarchical dependencies only go one
way, not having references both "down" and "up". The widget is at the
bottom of the hierarchy and is intentionally a fairly simple object. All
it has to know how to do is render itself into HTML, given an initial
value. The "smarts" of a field (e.g. validation) lie in the Field class
and tying fields together to make an holistic form is the Form class
(and above or next to that is the ModelForm class that knows how to make
a form from a model).
There's no need for a widget to know that something is a "model id",
since widgets don't care about models or what an id is. All it wants to
know is "what should I render?" However, one might want to pass the
model id down as some kind of initial data to a field and thus to the
widget for rendering.
When designing these sorts of things, it often helps to remember that
the same data "value" can move through a number of semantic roles: it's
a model id at the ModelForm level, say, but by the time a Widget
subclass is dealing with it, it's just initial data. Keeps things in
perspective.
Regards,
Malcolm
Something like:
group = Animal.objects.get(animal_group__id=XX)
But I don't know where you decide what XX is.
\d