New code:

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