Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Debian New Member Process
nm.debian.org
Commits
07a6d5d2
Commit
07a6d5d2
authored
Mar 13, 2012
by
Enrico Zini
Browse files
Try a custom field
parent
0e49a0ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/models.py
View file @
07a6d5d2
...
...
@@ -34,6 +34,30 @@ import datetime
# checked/enforced/recomputed during daily maintenance procedures
#
# See http://stackoverflow.com/questions/454436/unique-fields-that-allow-nulls-in-django
class
CharNullField
(
models
.
CharField
):
description
=
"CharField that stores NULL but returns ''"
# this is the value right out of the db, or an instance
def
to_python
(
self
,
value
):
if
isinstance
(
value
,
models
.
CharField
):
# if an instance, just return the instance
return
value
if
value
is
None
:
# if the db has a NULL, convert it into the Django-friendly '' string
return
""
else
:
# otherwise, return just the value
return
value
# catches value right before sending to db
def
get_db_prep_value
(
self
,
value
):
if
value
==
""
:
# if Django tries to save '' string, send the db None (NULL)
return
None
else
:
# otherwise, just pass the value
return
value
class
Person
(
models
.
Model
):
"""
...
...
@@ -74,7 +98,7 @@ class Person(models.Model):
# This is null for people who still have not picked one
uid
=
models
.
CharField
(
"Debian account name"
,
max_length
=
32
,
null
=
True
,
unique
=
True
,
blank
=
True
)
# OpenPGP fingerprint, NULL until one has been provided
fpr
=
models
.
CharField
(
"OpenPGP key fingerprint"
,
max_length
=
80
,
null
=
True
,
unique
=
True
,
blank
=
True
)
fpr
=
Char
Null
Field
(
"OpenPGP key fingerprint"
,
max_length
=
80
,
null
=
True
,
unique
=
True
,
blank
=
True
)
status
=
models
.
CharField
(
"current status in the project"
,
max_length
=
20
,
null
=
False
,
choices
=
[
x
[
1
:
3
]
for
x
in
const
.
ALL_STATUS
])
status_changed
=
models
.
DateTimeField
(
"when the status last changed"
,
null
=
False
,
default
=
datetime
.
datetime
.
utcnow
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment