Tuesday, November 1, 2011

Re: Set of choices of which several can be chosen without using a ManyToManyField

On 11/01/2011 09:05 AM, Jaroslav Dobrek wrote:
>> You are confusing model fields with form fields. MultipleChoiceField
>> is a form field, not a model field.
> I wasn't aware of the existence of MultipleChoiceFields. The idea of
> the above code was to express that I wanted to use this code
>
> class Candidate(models.Model):
>
> programming_languages = models.CharField(max_length=50, choices=(
>
> (u'Python)', u'Python'),
> (u'C++', u'C++'),
> (u'Java', u'Java'),
> # ...
> ), blank=True)
>
> with the only exception that, in the admin interface, several choices
> are possible when one creates a new candidate object. I.e. I want
> admins to be able to create a candidate that knows, say Python *and* C+
> + by choosing both of these languages during the creation of the
> object. I used the string "MultipleChoiceField" as a dummy for
> whatever should be used instead.
>
> Jaroslav
>
>
>
>
>
>
>> If you want a field that will be represented by a MultipleChoiceField
>> in model, you simply need to define 'choices' on a field class.
>>
>> https://docs.djangoproject.com/en/1.3/ref/models/fields/#choices
>>
>> Cheers
>>
>> Tom
Still, you want to control the input at the form level, not the model
level. Create a ModelForm for your Candidate, but override the language
field to take a MultipleChoiceField, and then override the __init__()
and save() methods to handle them properly. "Properly," of course, is
determined by your application, and how you want to store the
information in the database. You could choose to store it in a
CharField as a comma separated list of language names, or in an
IntegerField as a bit field (0x1 = 'Python', 0x2 = 'Perl', 0x4 = PHP, so
0x5 means the user knows Python and PHP, but not Perl). The latter is a
more efficient way to store the data, but the former is arguably more
human-friendly.

Ultimately, though, it seems that you are adding complexity rather than
removing it. This is exactly what many to many relationships are
designed to handle. If you want to use another method, you have to
figure out the details for yourself.

Cheers,
Cliff

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Set of choices of which several can be chosen without using a ManyToManyField

On Tue, Nov 1, 2011 at 1:05 PM, Jaroslav Dobrek
<jaroslav.dobrek@gmail.com> wrote:
>> You are confusing model fields with form fields. MultipleChoiceField
>> is a form field, not a model field.
>
> I wasn't aware of the existence of MultipleChoiceFields. The idea of
> the above code was to express that I wanted to use this code
>
> class Candidate(models.Model):
>
>    programming_languages = models.CharField(max_length=50, choices=(
>
>            (u'Python)', u'Python'),
>            (u'C++', u'C++'),
>            (u'Java', u'Java'),
>            # ...
>            ), blank=True)
>
> with the only exception that, in the admin interface, several choices
> are possible when one creates a new candidate object. I.e. I want
> admins to be able to create a candidate that knows, say Python *and* C+
> + by choosing both of these languages during the creation of the
> object. I used the string "MultipleChoiceField" as a dummy for
> whatever should be used instead.
>
> Jaroslav
>

That isn't possible with a single field using Django's default fields.
You want a ManyToManyField to a separate LanguageChoices model.

As an alternative, you could define a new field type that would use
MultipleChoiceField as the form field, and compresses and decompresses
from a single value. This would be a lot more work than simply
defining the additional model.

Cheers

Tom

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Set of choices of which several can be chosen without using a ManyToManyField

> You are confusing model fields with form fields. MultipleChoiceField
> is a form field, not a model field.

I wasn't aware of the existence of MultipleChoiceFields. The idea of
the above code was to express that I wanted to use this code

class Candidate(models.Model):

programming_languages = models.CharField(max_length=50, choices=(

(u'Python)', u'Python'),
(u'C++', u'C++'),
(u'Java', u'Java'),
# ...
), blank=True)

with the only exception that, in the admin interface, several choices
are possible when one creates a new candidate object. I.e. I want
admins to be able to create a candidate that knows, say Python *and* C+
+ by choosing both of these languages during the creation of the
object. I used the string "MultipleChoiceField" as a dummy for
whatever should be used instead.

Jaroslav


> If you want a field that will be represented by a MultipleChoiceField
> in model, you simply need to define 'choices' on a field class.
>
> https://docs.djangoproject.com/en/1.3/ref/models/fields/#choices
>
> Cheers
>
> Tom

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Closing all connections to DB.

Hi,

I want to close all connections to the database, because I develop a long running daemon process:

for connection in connections.all():
connection.close()

But the above code does not work.

select * from pg_stat_activity ; --> There Script is still "idle in transaction"


I found out, that deleting the connection objects solves the problem:

for connection in connections.all():
connection.close() # Der Server braucht keine DB-Verbindung. Ansonsten bleibt die ewig offen.
del(connection.connection)

Has someone seen this before?

Postgres Version 9.0.3
python-psycopg2 2.3.2

--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail
: guettli (*) thomas-guettler + de

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Set of choices of which several can be chosen without using a ManyToManyField

On Tue, Nov 1, 2011 at 11:07 AM, Jaroslav Dobrek
<jaroslav.dobrek@gmail.com> wrote:
> Hello,
>
> what is the most straightforward way to use a set of choices of which
> several can be chosen without using a ManyToManyField?
>
> Using a ManyToManyField would make my program unnecessarily
> complicated.
>
> Example:
>
> class Candidate(models.Model):
>
>    programming_languages = models.MultipleChoiceField(max_length=50,
> choices=( # replace MultipleChoiceField with existing possibility
>
>            (u'Python)', u'Python'),
>            (u'C++', u'C++'),
>            (u'Java', u'Java'),
>            # ...
>            ), blank=True)
>
> Jaroslav
>

You are confusing model fields with form fields. MultipleChoiceField
is a form field, not a model field.

If you want a field that will be represented by a MultipleChoiceField
in model, you simply need to define 'choices' on a field class.

https://docs.djangoproject.com/en/1.3/ref/models/fields/#choices

Cheers

Tom

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Disk I/O Error

On 1.11.2011 8:23, Nicole Button wrote:
> I'm getting a DatabaseError, looking like this:
>
> Django Version: 1.3
> Exception Type: DatabaseError
> Exception Value: disk I/O error
> Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/
> backends/sqlite3/base.py in execute, line 234
>
> whenever I try to read or write to any of the databases associated
> with any of the websites on one of our servers. The fact that all
> these websites work locally, but not in their live versions seems to
> suggest to me that something has gone wrong on the server, rather than
> with django, but I thought I'd better ask and see if any one has had
> any similar issues. I'm running python 2.6.6, django 1.3 and they're
> on a Linux server.
>

My wild guess is that you don't have permissions to write in db
directory... SQLite (if you're using it) requires read and write rights
to directory where actual database resides.

--

Jani Tiainen

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Set of choices of which several can be chosen without using a ManyToManyField

Hello,

what is the most straightforward way to use a set of choices of which
several can be chosen without using a ManyToManyField?

Using a ManyToManyField would make my program unnecessarily
complicated.

Example:

class Candidate(models.Model):

programming_languages = models.MultipleChoiceField(max_length=50,
choices=( # replace MultipleChoiceField with existing possibility

(u'Python)', u'Python'),
(u'C++', u'C++'),
(u'Java', u'Java'),
# ...
), blank=True)

Jaroslav

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.