inline formset
Hi, I'm a bit stuck with inline formset. I missed something. I'm using django 1.1.1. I have a model: class Address(models.Model): street = ... number = ... ... class Person(models.Model): first_name = ... last_name = address = models.ForeignKey(Address) ... Based on this model, I would like to have one form to add a person and her address. In order to achieve this, I'm using inline formset. As far as I understood, formset allows to add multiple form on a page and inline formset is an extension that allows to play with related objects. I written the following view (based on the documentation located at [1]) [1] http://docs.djangoproject.com/en/1.1/topics/forms/modelforms/#inline- formsets def add_person_form(request): address = Address() PersonFormSet = inlineformset_factory(Address, Person, max_num = 1, can_delete = False) if request.method == 'POST': formset = PersonFormSet(request.POST, request.FILES, instance = address) if formset.is_valid(): formset.save() return redirect('/person') else: formset = PersonFormSet(instance = address) return render_to_response('person/add_form.html', { "formset": formset } ) My template looks like (simplified version): {{ formset }} This only displays the person but not the address. Extra question: if I want to display the fields in a given order, let's say: first_name, last_name, and then all fields from Address object followed by the remaining fields from Person. What is the best way of doing it ? Thanks for your support, Frédéric Burlet. signature.asc Description: This is a digitally signed message part.
Re: Handling Vector/Array Data in Forms
On Saturday 09 January 2010 17:17:26 Tomasz Zieliński wrote: > On 9 Sty, 01:23, datta <dattatrey...@gmail.com> wrote: > > I am using Django for a scientific applicaition. If I have to > > transport a vector/array 'to' a form, dismantle it and display the > > relevant information, it is easy. But how I capture vectors/array > > datatypes 'from' the HTML forms (submitted by the user) in the > > view.class and work with them. > > > > i.e., i am asking if there is a efficient way of handling 'array' data > > types in forms (other than using a single variable name in the (html) > > form and doing a get_all from the (parent) request object) > > I'm not sure what you are asking for, but request.POST['vector'] > contains > list or tuple of values gathered from vector=1=2&(etc...) POST > data. Indeed, or have a look at QueryDict: http://docs.djangoproject.com/en/1.1/ref/request-response/#querydict-objects Frédéric Burlet. signature.asc Description: This is a digitally signed message part.
Re: {% if ... in ... %} template tags not working
Which version of django are you running ? The in operator in the if statement only works in the development version of django not with 1.1 or 1.0 series. (see warning on top of the page) Frédéric Burlet. On Saturday 09 January 2010 21:22:28 kotpierdzibonk wrote: > Hi, > > I copied the below code from the django documentation (http:// > docs.djangoproject.com/en/dev/ref/templates/builtins/), tried it out, > and it is not working for me. Can anyone think of a reason why? > > {% if "bc" in "abcdef" %} > This appears since "bc" is a substring of "abcdef" > {% endif %} > > > I get the following error: > > Exception Type: TemplateSyntaxError > Exception Value: 'if' statement improperly formatted > Exception Location: .../django/template/defaulttags.py in do_if, line > 822 > Python Executable:/usr/bin/python2.5 > Python Version: 2.5.4 > > > Django version 1.1.1 > signature.asc Description: This is a digitally signed message part.
Abstract model classes and foreign keys
Hi, I'm facing an issue when modeling a couple of tables by using abstract classes. Here is an extract of my model: class TypeConstant(models.Model): code = models.CharField(max_length = 8, unique = True) description = models.CharField(max_length = 32) class Meta: abstract = True class TypeConstantI18n(models.Model): code = models.ForeignKey(ConstantType, related_name = 'code') locale = models.CharField(max_length = 5) translation = models.CharField(max_length = 32) class Meta: abstract = True class Title(TypeConstant): pass class TitleI18n(TypeConstantI18n): pass But this obviously doesn't work since the ForeignKey in TypeConstantI18n points to an abstract class, it should be specific instead. I could solve my issue by adding the attribute "code" in each "TypeConstantI18n" subclasses but I'm wondering if there are no other way to do it. Maybe it's more a python programming issue than a django issue. I'm using django 1.1.1. Any hint will be appreciated. Frédéric Burlet. signature.asc Description: This is a digitally signed message part.
Re: django-audiorecorder ?
On Saturday 02 January 2010 10:55:11 Waqqas Jabbar wrote: > Hi, > > There are audio players available for djagon, but is there any django > project the provide audio recording capability? > My search has not produce any good results. > > There are some python based libraries liky PyAudio ( > http://people.csail.mit.edu/hubert/pyaudio/) or Gstreamer python binding, > that can be used. Can anyone give me some ideas on how to make one of my > own ? > > I want to record only short clip.Can javascript be used for audio recording > on client computer and the upload the file? > > peace > waqqas > > -- Hi, If your purpose is to record/read live stream via a website, I think it's then better to provide either a java applet or a flash application that help the user to record audio or video via your website. For flash applications, you can use red5[1] which is an open source flash server implemented in java. It allows you to record/read live streams through flash applications (If you are brave or feisty... you could implement this server in python ;) [1] http://osflash.org/red5 If you need to implement a client in flash, you can use openlazlo[2] or use an-already-existing client. I know that the dokeos[3] project has one but I never tried to compile it or install it myself. [2] http://www.openlaszlo.org/ [3] http://dokeos.svn.sourceforge.net/viewvc/dokeos/trunk/videoconference/ Hope this helps. Fred. signature.asc Description: This is a digitally signed message part.
ModelForm using ModelForm
Hi, I'm new in the python world and therefore in django. I'm using django 1.1.1. I started to write a small application and I have a question related to ModelForms. I defined two model objects: class Person(models.Model): first_name = ... last_name = ... address = models.ForeignKey(Address) ... class Address(models.Model): street = ... number = ... ... I would like to know whether it is possible to write something like this with forms.ModelForm. class AddressForm(forms.ModelForm): class Meta: model = Address class PersonForm(forms.ModelForm): address = AddressForm class Meta: model = Person I tested it but it doesn't seem to work. So I would like to know if we can do this or if I missed something to get it working. I didn't seen anything related to this in the documentation (or maybe I missed it). Thanks for your help. Fred. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.