|
List Info
Thread: BooleanField and MySQL default value
|
|
| BooleanField and MySQL default value |

|
2006-04-23 01:14:31 |
When I define a model:
>>> class Test(models.Model):
>>> ... some other fields ...
>>> bool_field = models.BooleanField(default=True)
Django generate next sql:
CREATE TABLE `test_test` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
... some other fields ...
`bool_field` bool NOT NULL
It doesn't generate the DEFAULT "1" part...
First I thought that the manipulator will authomaticly set
this to True
on save, but it doesn't.
Is this u bug?
--~--~---------~--~----~------------~-------~--~----~
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://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|
|
| BooleanField and MySQL default value |

|
2006-04-23 20:14:15 |
On 4/22/06, Viktor <alefnula gmail.com> wrote:
> When I define a model:
>
> >>> class Test(models.Model):
> >>> ... some other fields ...
> >>> bool_field =
models.BooleanField(default=True)
>
> Django generate next sql:
>
> CREATE TABLE `test_test` (
> `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> ... some other fields ...
> `bool_field` bool NOT NULL
>
> It doesn't generate the DEFAULT "1"
part...
Hi Viktor,
Default values aren't created at the SQL level -- they're
enforced at
the Django DB-API level.
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com
--~--~---------~--~----~------------~-------~--~----~
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://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|
|
| BooleanField and MySQL default value |

|
2006-04-23 20:51:01 |
On Sun, Apr 23, 2006 at 03:14:15PM -0500, Adrian Holovaty
wrote:
> Default values aren't created at the SQL level --
they're enforced at
> the Django DB-API level.
I thought that was only enforced by the admin functionality
and that
if I wanted a default value for my views I'd have to write
it myself
into the model or view.
I found it unclear to me which field settings were enforced
by the
admin functionaility, the DB-API, or the SQL DB level. This
should be
made VERY clear in the docs, and when within the DB-API it
should also
be crystal clear when/how to override either that
functionality or the
method within which that enforcement is done (and then, when
overriding those methods how to invoke the parent's methods
too).
--
Glenn
--~--~---------~--~----~------------~-------~--~----~
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://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|
|
| BooleanField and MySQL default value |

|
2006-04-23 21:12:29 |
Adrian Holovaty wrote:
> Default values aren't created at the SQL level --
they're enforced at
> the Django DB-API level.
OK, I figured that out the meantime, but it doesn't work
for the
BooleanField.
When I define the default value for my BooleanField to True
and then
create an object this field is set to False.
Here is the complete test source snippet:
models.py
...........................................................
class Person(models.Model):
name = models.CharField(maxlength=255)
stupid = models.BooleanField(default=True)
...........................................................
views.py
............................................................
def add(request):
manipulator = Person.AddManipulator()
if request.POST:
data = request.POST.copy()
errors = manipulator.get_validation_errors(data)
if not errors:
manipulator.do_html2python(data)
manipulator.save(data)
return HttpResponseRedirect('/')
else:
errors = data = {}
form = FormWrapper(manipulator, data, errors)
return render_to_response('add.html', {'form' :
form})
............................................................
..
add.html
............................................................
....
<html>
<body>
<form action="/add/"
method="post">
Name: {{ form.name }}
<input type="submit"
value="Submit" />
</form>
</body>
</html>
............................................................
......
--~--~---------~--~----~------------~-------~--~----~
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://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|
|
| BooleanField and MySQL default value |

|
2006-04-26 12:13:55 |
OK, I found the problem...
The problem is that manipulators don't look for the default
value of the
field if the field isn't set as editable=False, which is
bad because I
may (I have) objects that can be created by different users,
and not all
users can set all attributes. When some group of users
create an object
I want it to have some default values which can't be set by
that user
(and I defined them in my model with default=some_value),
but if I set
the field as editable=False, then some other user (with
admin roles)
would not be able to set that fields too.
Hidden fields are bad, because user can send POST request
with those
fields set the way (s)he wants. And setting this fields in
views is also
bad because it's oppose the DRY principle.
I think that the most cleaner solutions is that the
AddManipulator
always looks for default values if some values are not
submited, not
just when the editable is set to False.
--~--~---------~--~----~------------~-------~--~----~
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://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
|
|
[1-5]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|