Files
2012-02-21 01:15:00 -05:00

1 line
1.9 KiB
JSON

[{"user_id": 7, "stars": [], "topic_id": 6393, "date_created": 1297871804.42641, "message": "advisable for doing what?", "group_id": 81, "id": 120966}, {"user_id": 7, "stars": [], "topic_id": 6393, "date_created": 1297871306.7499189, "message": "if you're on django 1.1 use django.utils.importlib.import_module", "group_id": 81, "id": 120909}, {"user_id": 5108, "stars": [], "topic_id": 6393, "date_created": 1297871202.819984, "message": "I have a Django app that ships with a default form class, but I want users to be able to swap this by putting something like ``MYAPP_FORM_CLASS = \"some.custom.forms.MyForm\"`` in their project's settings.py.\n\nIn myapp/settings.py I have something like\n\n from django.conf import settings\n FORM_CLASS = getattr(settings, 'MYAPP_FORM_CLASS', \"%s.forms.MyDefaultForm\" % __package__)\n\nand in myapp/views.py I have something like\n\n from .settings import FORM_CLASS\n forms_module, sep, form_class = FORM_CLASS.rpartition('.')\n form = getattr(__import__(forms_module, [], [], form_class), form_class)\n\nThis works but looks kind of scary to me. Is this the way to go?", "group_id": 81, "id": 120899}, {"user_id": 7, "stars": [{"date_created": 1297883425.2974839, "user_id": 141}], "topic_id": 6393, "date_created": 1297871328.924284, "message": "getattr(import_module(forms_model), form_class)", "group_id": 81, "id": 120916}, {"user_id": 7, "stars": [], "topic_id": 6393, "date_created": 1297871348.8335929, "message": "also, use rsplit(\".\", 1) rather than rpartition so you don't get sep", "group_id": 81, "id": 120919}, {"user_id": 5108, "stars": [], "topic_id": 6393, "date_created": 1297871397.3620081, "message": "ah, cool. thanks for the heads up.", "group_id": 81, "id": 120925}, {"user_id": 5108, "stars": [], "topic_id": 6393, "date_created": 1297871652.759882, "message": "\u2026 and is using \"%s.forms.MyDefaultForm\" % __package__ advisable?", "group_id": 81, "id": 120941}]