>
>
> It probably is related to the this being a foreign key field and in
> order for it to produce a valid object instance from the Target model,
> it needs a queryset. Try to subclass from ModelChoiceField[1] and see
> if that works.
>
> [1]
> http://code.djangoproject.com/browser/django/trunk/django/forms/models.py#L891
>
>
Code now:

from django.forms.widgets import Select
from django.forms.models import ModelChoiceField

from Server_Automation.target_mgmt.models import Target

class AutoCompleteWidget(Select):

    def render(self, name, value, attrs=None, choices=()):
        logger.debug(value)     # Logs 1 (the id)
        logger.debug(choices)   # Logs and empty tuple

        super(AutoCompleteWidget, self).render(name, value, choices)

class AutoCompleteField(ModelChoiceField):
    widget = AutoCompleteWidget

class TicketForm(ModelForm):

    target = AutoCompleteField(queryset=Target.objects.all())

    class Meta:
        model = Ticket
        exclude = ('slug',)

For a reason I ignore, my model just doesn't want to pass the choices to the
widget and it takes the default value (an empty tuple). I verified this by
changing the default value and checking the log.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to