How to add auto id to django model form -
my django model default has auto generated id field primary key named 'id' default on db.
as such model has lot of other fields selectively displaying using django model form. while doing specify 'id' auto generated id field form not display or generate field on html @ though seems recognize valid field.
i have checked doing 'all' fields not bringing in specific field. funny thing django seem recognize field 'id' because if change 'id' or else random gives me error example "unknown field(s) (id) specified for....." on forms.py
this 'id' important using link , retrieve related objects using ajax on client side. if not work forced use field primary key. suggestions?
i ended using workaround suggested 'mastazi' passing id hidden field.
all did access hidden field , generate html element. since using crispy_forms layout able use html element under layout.
form_id= self.instance.id id_hidden = '<input type="hidden" id="form_id" value=' + str(form_id) +' />'
i not sure if perfect solution works.
Comments
Post a Comment