Form is invalid when using get_item_id function

17 views
Skip to first unread message

saranya k

unread,
Jan 2, 2015, 1:40:07 AM1/2/15
to django-s...@googlegroups.com
STUDENT      
========
id
Name

STUDENT_SECTION:
===============
id
Student (FK of student)
class_section


LOOKUP:
========
class StudentLookup(ModelLookup):
    model = StudentSection

    def get_item_id(self,item) :    
        return item.student.id

FORM:
=====
class StudentFilterForm(forms.Form): 
    student =  student=selectable.AutoCompleteSelectMultipleField(
                lookup_class=StudentLookup,
                required = False,
                )


When using get_item_id function in  lookup , form is invalid , but without this get_item_id function form is valid.

Then I used get_item function in lookup which made the form valid, but value of the student field in form   is StudentSection table PK not Student table PK.

class StudentLookup(ModelLookup):
    model = StudentSection

    def get_item_id(self,item) :    
        return item.student.id

    def get_item(self,value) :
        return StudentSection.objects.get(student=value)

Reply all
Reply to author
Forward
0 new messages