mirror of
https://github.com/not-kennethreitz/convore.json.git
synced 2026-06-05 23:20:19 +00:00
1 line
2.6 KiB
JSON
1 line
2.6 KiB
JSON
[{"user_id": 1736, "stars": [], "topic_id": 15437, "date_created": 1301120737.5644989, "message": "As I found out tonight, there is no good way in Django to have a form widget who's output depends on more than just the value of its field. In my case I need the instance on my modelform to get the allowed values. Is there a better way to handle this than wrapping the whole form in a custom inclusion tag?", "group_id": 81, "id": 445275}, {"user_id": 25337, "stars": [], "topic_id": 15437, "date_created": 1301128359.8727169, "message": "Can you describe in a bit more detail what you mean? A select widget can access the allowed values without needing anything special like a template tag, for example.", "group_id": 81, "id": 445665}, {"user_id": 23244, "stars": [{"date_created": 1301148226.756021, "user_id": 3354}, {"date_created": 1301204248.450067, "user_id": 18417}], "topic_id": 15437, "date_created": 1301136449.1082289, "message": "Define an init method on the Form subclass manipulating the fields attribute. Alternatively, for a more DRY approach, subclass the Field and/or Widget class and override their init methods. I used the former approach to fill a model", "group_id": 81, "id": 445865}, {"user_id": 23244, "stars": [], "topic_id": 15437, "date_created": 1301136525.39622, "message": "Cont... fill a model select with choices depending on the logged in user (I passed the user along in the form's init method)", "group_id": 81, "id": 445869}, {"user_id": 1736, "stars": [], "topic_id": 15437, "date_created": 1301169246.1628151, "message": "@ulmus Something like this might work, but it is certainly a hack :-/", "group_id": 81, "id": 447317}, {"user_id": 1736, "stars": [], "topic_id": 15437, "date_created": 1301169248.429594, "message": "def __init__(self, *args, **kwargs):\n super(MyForm, self).__init__(*args, **kwargs)\n self.fields['run_list'] = copy.copy(self.fields['run_list'])\n self.fields['run_list'].widget = MyWidget(instance=self.instance)\n", "group_id": 81, "id": 447318}, {"user_id": 1736, "stars": [], "topic_id": 15437, "date_created": 1301190768.1712611, "message": "Upon further code diving I see that self.fields is actually already an instance copy, so this feels a lot less hacky.", "group_id": 81, "id": 448986}, {"user_id": 1822, "stars": [{"date_created": 1301192916.3488369, "user_id": 1736}, {"date_created": 1301203729.6519599, "user_id": 3354}, {"date_created": 1301204289.584161, "user_id": 18417}, {"date_created": 1301388461.5981519, "user_id": 15180}], "topic_id": 15437, "date_created": 1301192747.683018, "message": "The mother post on this technique is: http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/", "group_id": 81, "id": 449046}] |