I want the same add new functionality as model foreign key select
boxes in admin, there the select widget is passed through
django.contrib.admin.widgets.RelatedFieldWidgetWrapper to add the
additional html (image, links etc).
The __init__.py takes the admin_site instance, I want this
functionality for my site, not admin area so I'm trying to extend the
class and override the init method so admin_site is not required.
from django.contrib.admin.widgets import RelatedFieldWidgetWrapper
class MyRelatedFieldWidgetWrapper(RelatedFieldWidgetWrapper):
"""
This class is a wrapper to a given widget to add the add icon.
"""
def __init__(self, widget, rel):
self.is_hidden = widget.is_hidden
self.needs_multipart_form = widget.needs_multipart_form
self.attrs = widget.attrs
self.choices = widget.choices
self.widget = widget
self.rel = rel
And here's how I'm using it
class DDCForm(forms.ModelForm):
"""
Enables a form to be created from the model
"""
location = forms.ModelChoiceField(Location.objects.all(), >>>
widget=widgets.MyRelatedFieldWidgetWrapper(forms.Select(),XXX))
class Meta:
model = DDC
I don't know what to replace XXX with, I know it's a db_field
<django.db.models.fields.AutoField object at 0x1518150> but I don't
know how/where to get it from.
--
You received this message because you are subscribed to the Google Groups
"Django 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/django-users?hl=en.