Creating formsets through AJAX
Hi, I am running into an annoying problem when trying to create formsets dynamically. I have a script that sends JSON data to a view to render it as a formset. The response is then inserted in the page: Script: data = JSON.stringify([1, 2, 3]); $("#container").load("render-form/", {data: data}); View: def render_form(request): data = simplejson.loads(request.POST["data"]) objs = [SomeModel(i) for i in data] FormSet = modelformset_factory(SomeModel, extra=0) forms = FormSet(queryset=objs) return render_to_response("form_template.html", {"forms": forms}) It works but I get incorrect ManagementForm data in the output: For django to save the formset correctly when it is submitted, I have to manually set INITIAL_FORMS to 0 in javascript (because the objects are not really in the database). I tried to create the formset using extra=3 and passing the data via the 'initial' argument, but this gives an IndexError (django is trying to set the forms 'instance' attribute from the queryset, but it is empty). Is there a less hackish way to do this ? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Format dates using a specific locales under mod_python
By default, dates are formated in English (things like .strftime("%A") return days names in English). I tried to put locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8') in the settings file and it works well on the development server. The problem is under mod_python dates are printed in the selected locale for a while (~2 minutes), then for some strange reason I get English dates again. Maybe there is a mod_python setting to permanently set the locale ? -- Lup --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Format dates using a specific locales under mod_python
2009/5/29 Graham Dumpleton : > > > > On May 28, 10:16 pm, luper rouch wrote: >> By default, dates are formated in English (things like .strftime("%A") >> return days names in English). >> >> I tried to put locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8') in the >> settings file and it works well on the development server. The problem >> is under mod_python dates are printed in the selected locale for a >> while (~2 minutes), then for some strange reason I get English dates >> again. >> >> Maybe there is a mod_python setting to permanently set the locale ? > > It is likely because you have some other application also being hosted > under the same Apache, be it a Python web application, or even a PHP > application, which is changing the locale settings. > > This is an issue with mod_wsgi as well and described in: > > http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Timezone_and_Locale_Settings > > For mod_wsgi, if you need to run an application with different > timezone, locale or language settings than other applications, you > must isolate that application into its own process group using > mod_wsgi daemon mode. You can't do this with mod_python of mod_wsgi > embedded mode. > > Graham Oh thanks, now I understand why Django uses its own date formating functions. I think I will replace all my .strftime() with django.utils.dateformat.format(), I don't like the idea to require unusual server configuration for my app. -- Lup --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Serializing custom fields
I have a db.models.Field subclass that needs a special representation in the database. This is achieved by implementing get_db_prep_save() and using SubfieldBase as the metaclass, and works fine. The problem comes when serializing, the custom field is serialized using the python's form string representation of the data. I tried to implement flatten_data() in the custom field, as it seems [1] to be the serialization counterpart of get_db_prep_save(), but the method is not called. Strangely if I don't use SubfieldBase as the metaclass, flatten_data() is called and the data is correctly serialized, but then the database part is broken ... Am I doing something wrong ? [1] http://www.djangoproject.com/documentation/custom_model_fields/#flatten-data-self-follow-obj-none --Luper --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Applications imports best practices ?
Hi list, What is the proper way to import modules within an application ? For example if I have a project "foo" containing an application "bar", how should I import things in bar's modules ? 1. import foo.bar.module the source code has to be modified when using bar in another project 2. import bar.module the application is more portable, but its path has to be included in PYTHON_PATH (at least under mod_python) I feel like I am missing a more elegant solution :-) Luper --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---