Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
50acbf3f
Kaydet (Commit)
50acbf3f
authored
Eyl 26, 2015
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Made tests/serializers/models.py a models package
Thanks Tim Graham for the patch series review.
üst
4908222a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
207 additions
and
203 deletions
+207
-203
__init__.py
tests/serializers/models/__init__.py
+3
-0
base.py
tests/serializers/models/base.py
+178
-0
data.py
tests/serializers/models/data.py
+5
-203
natural.py
tests/serializers/models/natural.py
+21
-0
No files found.
tests/serializers/models/__init__.py
0 → 100644
Dosyayı görüntüle @
50acbf3f
from
.base
import
*
# NOQA
from
.data
import
*
# NOQA
from
.natural
import
*
# NOQA
tests/serializers/models/base.py
0 → 100644
Dosyayı görüntüle @
50acbf3f
"""
Serialization
``django.core.serializers`` provides interfaces to converting Django
``QuerySet`` objects to and from "flat" data (i.e. strings).
"""
from
__future__
import
unicode_literals
from
decimal
import
Decimal
from
django.db
import
models
from
django.utils
import
six
from
django.utils.encoding
import
python_2_unicode_compatible
class
CategoryMetaDataManager
(
models
.
Manager
):
def
get_by_natural_key
(
self
,
kind
,
name
):
return
self
.
get
(
kind
=
kind
,
name
=
name
)
@python_2_unicode_compatible
class
CategoryMetaData
(
models
.
Model
):
kind
=
models
.
CharField
(
max_length
=
10
)
name
=
models
.
CharField
(
max_length
=
10
)
value
=
models
.
CharField
(
max_length
=
10
)
objects
=
CategoryMetaDataManager
()
class
Meta
:
unique_together
=
((
'kind'
,
'name'
),)
def
__str__
(
self
):
return
'[
%
s:
%
s]=
%
s'
%
(
self
.
kind
,
self
.
name
,
self
.
value
)
def
natural_key
(
self
):
return
(
self
.
kind
,
self
.
name
)
@python_2_unicode_compatible
class
Category
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
)
meta_data
=
models
.
ForeignKey
(
CategoryMetaData
,
models
.
SET_NULL
,
null
=
True
,
default
=
None
)
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
@python_2_unicode_compatible
class
Author
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
)
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
@python_2_unicode_compatible
class
Article
(
models
.
Model
):
author
=
models
.
ForeignKey
(
Author
,
models
.
CASCADE
)
headline
=
models
.
CharField
(
max_length
=
50
)
pub_date
=
models
.
DateTimeField
()
categories
=
models
.
ManyToManyField
(
Category
)
meta_data
=
models
.
ManyToManyField
(
CategoryMetaData
)
class
Meta
:
ordering
=
(
'pub_date'
,)
def
__str__
(
self
):
return
self
.
headline
@python_2_unicode_compatible
class
AuthorProfile
(
models
.
Model
):
author
=
models
.
OneToOneField
(
Author
,
models
.
CASCADE
,
primary_key
=
True
)
date_of_birth
=
models
.
DateField
()
def
__str__
(
self
):
return
"Profile of
%
s"
%
self
.
author
@python_2_unicode_compatible
class
Actor
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
,
primary_key
=
True
)
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
@python_2_unicode_compatible
class
Movie
(
models
.
Model
):
actor
=
models
.
ForeignKey
(
Actor
,
models
.
CASCADE
)
title
=
models
.
CharField
(
max_length
=
50
)
price
=
models
.
DecimalField
(
max_digits
=
6
,
decimal_places
=
2
,
default
=
Decimal
(
'0.00'
))
class
Meta
:
ordering
=
(
'title'
,)
def
__str__
(
self
):
return
self
.
title
class
Score
(
models
.
Model
):
score
=
models
.
FloatField
()
@python_2_unicode_compatible
class
Team
(
object
):
def
__init__
(
self
,
title
):
self
.
title
=
title
def
__str__
(
self
):
raise
NotImplementedError
(
"Not so simple"
)
def
to_string
(
self
):
return
"
%
s"
%
self
.
title
class
TeamField
(
models
.
CharField
):
def
__init__
(
self
):
super
(
TeamField
,
self
)
.
__init__
(
max_length
=
100
)
def
get_db_prep_save
(
self
,
value
,
connection
):
return
six
.
text_type
(
value
.
title
)
def
to_python
(
self
,
value
):
if
isinstance
(
value
,
Team
):
return
value
return
Team
(
value
)
def
from_db_value
(
self
,
value
,
expression
,
connection
,
context
):
return
Team
(
value
)
def
value_to_string
(
self
,
obj
):
return
self
.
value_from_object
(
obj
)
.
to_string
()
def
deconstruct
(
self
):
name
,
path
,
args
,
kwargs
=
super
(
TeamField
,
self
)
.
deconstruct
()
del
kwargs
[
'max_length'
]
return
name
,
path
,
args
,
kwargs
@python_2_unicode_compatible
class
Player
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
rank
=
models
.
IntegerField
()
team
=
TeamField
()
def
__str__
(
self
):
return
'
%
s (
%
d) playing for
%
s'
%
(
self
.
name
,
self
.
rank
,
self
.
team
.
to_string
())
class
BaseModel
(
models
.
Model
):
parent_data
=
models
.
IntegerField
()
class
ProxyBaseModel
(
BaseModel
):
class
Meta
:
proxy
=
True
class
ProxyProxyBaseModel
(
ProxyBaseModel
):
class
Meta
:
proxy
=
True
class
ComplexModel
(
models
.
Model
):
field1
=
models
.
CharField
(
max_length
=
10
)
field2
=
models
.
CharField
(
max_length
=
10
)
field3
=
models
.
CharField
(
max_length
=
10
)
tests/serializers/models.py
→
tests/serializers/models
/data
.py
Dosyayı görüntüle @
50acbf3f
# -*- coding: utf-8 -*-
"""
Serialization
``django.core.serializers`` provides interfaces to converting Django
``QuerySet`` objects to and from "flat" data (i.e. strings)
.
******** Models for test_data.py ***********
The following classes are for testing basic data marshalling, including
NULL values, where allowed.
The basic idea is to have a model for each Django data type
.
"""
from
__future__
import
unicode_literals
from
decimal
import
Decimal
from
django.contrib.contenttypes.fields
import
(
GenericForeignKey
,
GenericRelation
,
)
from
django.contrib.contenttypes.models
import
ContentType
from
django.db
import
models
from
django.utils
import
six
from
django.utils.encoding
import
python_2_unicode_compatible
class
CategoryMetaDataManager
(
models
.
Manager
):
def
get_by_natural_key
(
self
,
kind
,
name
):
return
self
.
get
(
kind
=
kind
,
name
=
name
)
@python_2_unicode_compatible
class
CategoryMetaData
(
models
.
Model
):
kind
=
models
.
CharField
(
max_length
=
10
)
name
=
models
.
CharField
(
max_length
=
10
)
value
=
models
.
CharField
(
max_length
=
10
)
objects
=
CategoryMetaDataManager
()
class
Meta
:
unique_together
=
((
'kind'
,
'name'
),)
def
__str__
(
self
):
return
'[
%
s:
%
s]=
%
s'
%
(
self
.
kind
,
self
.
name
,
self
.
value
)
def
natural_key
(
self
):
return
(
self
.
kind
,
self
.
name
)
@python_2_unicode_compatible
class
Category
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
)
meta_data
=
models
.
ForeignKey
(
CategoryMetaData
,
models
.
SET_NULL
,
null
=
True
,
default
=
None
)
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
@python_2_unicode_compatible
class
Author
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
)
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
@python_2_unicode_compatible
class
Article
(
models
.
Model
):
author
=
models
.
ForeignKey
(
Author
,
models
.
CASCADE
)
headline
=
models
.
CharField
(
max_length
=
50
)
pub_date
=
models
.
DateTimeField
()
categories
=
models
.
ManyToManyField
(
Category
)
meta_data
=
models
.
ManyToManyField
(
CategoryMetaData
)
class
Meta
:
ordering
=
(
'pub_date'
,)
def
__str__
(
self
):
return
self
.
headline
@python_2_unicode_compatible
class
AuthorProfile
(
models
.
Model
):
author
=
models
.
OneToOneField
(
Author
,
models
.
CASCADE
,
primary_key
=
True
)
date_of_birth
=
models
.
DateField
()
def
__str__
(
self
):
return
"Profile of
%
s"
%
self
.
author
@python_2_unicode_compatible
class
Actor
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
,
primary_key
=
True
)
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
@python_2_unicode_compatible
class
Movie
(
models
.
Model
):
actor
=
models
.
ForeignKey
(
Actor
,
models
.
CASCADE
)
title
=
models
.
CharField
(
max_length
=
50
)
price
=
models
.
DecimalField
(
max_digits
=
6
,
decimal_places
=
2
,
default
=
Decimal
(
'0.00'
))
class
Meta
:
ordering
=
(
'title'
,)
def
__str__
(
self
):
return
self
.
title
class
Score
(
models
.
Model
):
score
=
models
.
FloatField
()
from
.base
import
BaseModel
@python_2_unicode_compatible
class
Team
(
object
):
def
__init__
(
self
,
title
):
self
.
title
=
title
def
__str__
(
self
):
raise
NotImplementedError
(
"Not so simple"
)
def
to_string
(
self
):
return
"
%
s"
%
self
.
title
class
TeamField
(
models
.
CharField
):
def
__init__
(
self
):
super
(
TeamField
,
self
)
.
__init__
(
max_length
=
100
)
def
get_db_prep_save
(
self
,
value
,
connection
):
return
six
.
text_type
(
value
.
title
)
def
to_python
(
self
,
value
):
if
isinstance
(
value
,
Team
):
return
value
return
Team
(
value
)
def
from_db_value
(
self
,
value
,
expression
,
connection
,
context
):
return
Team
(
value
)
def
value_to_string
(
self
,
obj
):
return
self
.
value_from_object
(
obj
)
.
to_string
()
def
deconstruct
(
self
):
name
,
path
,
args
,
kwargs
=
super
(
TeamField
,
self
)
.
deconstruct
()
del
kwargs
[
'max_length'
]
return
name
,
path
,
args
,
kwargs
@python_2_unicode_compatible
class
Player
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
rank
=
models
.
IntegerField
()
team
=
TeamField
()
def
__str__
(
self
):
return
'
%
s (
%
d) playing for
%
s'
%
(
self
.
name
,
self
.
rank
,
self
.
team
.
to_string
())
class
BaseModel
(
models
.
Model
):
parent_data
=
models
.
IntegerField
()
class
ProxyBaseModel
(
BaseModel
):
class
Meta
:
proxy
=
True
class
ProxyProxyBaseModel
(
ProxyBaseModel
):
class
Meta
:
proxy
=
True
class
ComplexModel
(
models
.
Model
):
field1
=
models
.
CharField
(
max_length
=
10
)
field2
=
models
.
CharField
(
max_length
=
10
)
field3
=
models
.
CharField
(
max_length
=
10
)
# ******** Models for test_natural.py ***********
class
NaturalKeyAnchorManager
(
models
.
Manager
):
def
get_by_natural_key
(
self
,
data
):
return
self
.
get
(
data
=
data
)
class
NaturalKeyAnchor
(
models
.
Model
):
objects
=
NaturalKeyAnchorManager
()
data
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
)
title
=
models
.
CharField
(
max_length
=
100
,
null
=
True
)
def
natural_key
(
self
):
return
(
self
.
data
,)
class
FKDataNaturalKey
(
models
.
Model
):
data
=
models
.
ForeignKey
(
NaturalKeyAnchor
,
models
.
SET_NULL
,
null
=
True
)
# ******** Models for test_data.py ***********
# The following classes are for testing basic data marshalling, including
# NULL values, where allowed.
# The basic idea is to have a model for each Django data type.
class
BinaryData
(
models
.
Model
):
data
=
models
.
BinaryField
(
null
=
True
)
...
...
@@ -490,10 +296,6 @@ class InheritAbstractModel(AbstractBaseModel):
child_data
=
models
.
IntegerField
()
class
BaseModel
(
models
.
Model
):
parent_data
=
models
.
IntegerField
()
class
InheritBaseModel
(
BaseModel
):
child_data
=
models
.
IntegerField
()
...
...
tests/serializers/models/natural.py
0 → 100644
Dosyayı görüntüle @
50acbf3f
"""Models for test_natural.py"""
from
django.db
import
models
class
NaturalKeyAnchorManager
(
models
.
Manager
):
def
get_by_natural_key
(
self
,
data
):
return
self
.
get
(
data
=
data
)
class
NaturalKeyAnchor
(
models
.
Model
):
objects
=
NaturalKeyAnchorManager
()
data
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
)
title
=
models
.
CharField
(
max_length
=
100
,
null
=
True
)
def
natural_key
(
self
):
return
(
self
.
data
,)
class
FKDataNaturalKey
(
models
.
Model
):
data
=
models
.
ForeignKey
(
NaturalKeyAnchor
,
models
.
SET_NULL
,
null
=
True
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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