Re: Form foreign key add new
> I don't know what to replace XXX with, I know it's a db_field > but I don't > know how/where to get it from. AutoFields are the auto-incrementing primary key of your model. By default, your models get an automatic "id" attribute, which is what this is. Django frequently deals with the raw database objects, instead of their values. I've never tried to do what you're trying to accomplish, so I'm not sure that I have much else to suggest. Tim On Nov 25, 9:25 am, cerberos wrote: > 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 > 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 django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Form foreign key add new
I've realised I can't inherit from RelatedFieldWidgetWrapper because I want to override __init__ so I've copies the entire class an made a few changes. Still need to know what to pass in for rel. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Form foreign key add new
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 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 django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.