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
e817ae74
Kaydet (Commit)
e817ae74
authored
Ara 28, 2018
tarafından
Matt Wiens
Kaydeden (comit)
Tim Graham
Ara 28, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Followed style guide for model attribute ordering.
üst
dd8ed641
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
148 additions
and
135 deletions
+148
-135
base_user.py
django/contrib/auth/base_user.py
+7
-7
models.py
django/contrib/auth/models.py
+1
-0
models.py
django/contrib/gis/db/backends/oracle/models.py
+3
-3
models.py
django/contrib/gis/db/backends/postgis/models.py
+9
-5
models.py
django/contrib/gis/db/backends/spatialite/models.py
+13
-9
models.py
django/contrib/sites/models.py
+1
-0
many_to_many.txt
docs/topics/db/examples/many_to_many.txt
+6
-6
serialization.txt
docs/topics/serialization.txt
+6
-8
models.py
tests/admin_views/models.py
+3
-3
models.py
tests/admin_widgets/models.py
+3
-3
models.py
tests/custom_columns/models.py
+6
-6
models.py
tests/fixtures/models.py
+12
-12
__init__.py
tests/fixtures_model_package/models/__init__.py
+3
-3
models.py
tests/fixtures_regress/models.py
+5
-2
models.py
tests/introspection/models.py
+3
-3
models.py
tests/m2m_and_m2o/models.py
+3
-3
models.py
tests/m2m_regress/models.py
+3
-3
models.py
tests/m2m_through/models.py
+3
-3
models.py
tests/m2m_through_regress/models.py
+3
-3
models.py
tests/many_to_many/models.py
+6
-6
models.py
tests/many_to_one/models.py
+3
-3
models.py
tests/model_forms/models.py
+3
-3
models.py
tests/model_formsets/models.py
+3
-3
models.py
tests/multiple_database/models.py
+14
-12
models.py
tests/null_fk_ordering/models.py
+3
-3
models.py
tests/prefetch_related/models.py
+21
-21
natural.py
tests/serializers/models/natural.py
+2
-2
No files found.
django/contrib/auth/base_user.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -59,22 +59,22 @@ class AbstractBaseUser(models.Model):
class
Meta
:
abstract
=
True
def
get_username
(
self
):
"Return the identifying username for this User"
return
getattr
(
self
,
self
.
USERNAME_FIELD
)
def
__str__
(
self
):
return
self
.
get_username
()
def
clean
(
self
):
setattr
(
self
,
self
.
USERNAME_FIELD
,
self
.
normalize_username
(
self
.
get_username
()))
def
save
(
self
,
*
args
,
**
kwargs
):
super
()
.
save
(
*
args
,
**
kwargs
)
if
self
.
_password
is
not
None
:
password_validation
.
password_changed
(
self
.
_password
,
self
)
self
.
_password
=
None
def
get_username
(
self
):
"""Return the username for this User."""
return
getattr
(
self
,
self
.
USERNAME_FIELD
)
def
clean
(
self
):
setattr
(
self
,
self
.
USERNAME_FIELD
,
self
.
normalize_username
(
self
.
get_username
()))
def
natural_key
(
self
):
return
(
self
.
get_username
(),)
...
...
django/contrib/auth/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -60,6 +60,7 @@ class Permission(models.Model):
verbose_name
=
_
(
'content type'
),
)
codename
=
models
.
CharField
(
_
(
'codename'
),
max_length
=
100
)
objects
=
PermissionManager
()
class
Meta
:
...
...
django/contrib/gis/db/backends/oracle/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -23,6 +23,9 @@ class OracleGeometryColumns(models.Model):
db_table
=
'USER_SDO_GEOM_METADATA'
managed
=
False
def
__str__
(
self
):
return
'
%
s -
%
s (SRID:
%
s)'
%
(
self
.
table_name
,
self
.
column_name
,
self
.
srid
)
@classmethod
def
table_name_col
(
cls
):
"""
...
...
@@ -39,9 +42,6 @@ class OracleGeometryColumns(models.Model):
"""
return
'column_name'
def
__str__
(
self
):
return
'
%
s -
%
s (SRID:
%
s)'
%
(
self
.
table_name
,
self
.
column_name
,
self
.
srid
)
class
OracleSpatialRefSys
(
models
.
Model
,
SpatialRefSysMixin
):
"Maps to the Oracle MDSYS.CS_SRS table."
...
...
django/contrib/gis/db/backends/postgis/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -23,6 +23,15 @@ class PostGISGeometryColumns(models.Model):
db_table
=
'geometry_columns'
managed
=
False
def
__str__
(
self
):
return
'
%
s.
%
s -
%
dD
%
s field (SRID:
%
d)'
%
(
self
.
f_table_name
,
self
.
f_geometry_column
,
self
.
coord_dimension
,
self
.
type
,
self
.
srid
,
)
@classmethod
def
table_name_col
(
cls
):
"""
...
...
@@ -39,11 +48,6 @@ class PostGISGeometryColumns(models.Model):
"""
return
'f_geometry_column'
def
__str__
(
self
):
return
"
%
s.
%
s -
%
dD
%
s field (SRID:
%
d)"
%
\
(
self
.
f_table_name
,
self
.
f_geometry_column
,
self
.
coord_dimension
,
self
.
type
,
self
.
srid
)
class
PostGISSpatialRefSys
(
models
.
Model
,
SpatialRefSysMixin
):
"""
...
...
django/contrib/gis/db/backends/spatialite/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -21,6 +21,15 @@ class SpatialiteGeometryColumns(models.Model):
db_table
=
'geometry_columns'
managed
=
False
def
__str__
(
self
):
return
'
%
s.
%
s -
%
dD
%
s field (SRID:
%
d)'
%
(
self
.
f_table_name
,
self
.
f_geometry_column
,
self
.
coord_dimension
,
self
.
type
,
self
.
srid
,
)
@classmethod
def
table_name_col
(
cls
):
"""
...
...
@@ -37,11 +46,6 @@ class SpatialiteGeometryColumns(models.Model):
"""
return
'f_geometry_column'
def
__str__
(
self
):
return
"
%
s.
%
s -
%
dD
%
s field (SRID:
%
d)"
%
\
(
self
.
f_table_name
,
self
.
f_geometry_column
,
self
.
coord_dimension
,
self
.
type
,
self
.
srid
)
class
SpatialiteSpatialRefSys
(
models
.
Model
,
SpatialRefSysMixin
):
"""
...
...
@@ -54,11 +58,11 @@ class SpatialiteSpatialRefSys(models.Model, SpatialRefSysMixin):
proj4text
=
models
.
CharField
(
max_length
=
2048
)
srtext
=
models
.
CharField
(
max_length
=
2048
)
@property
def
wkt
(
self
):
return
self
.
srtext
class
Meta
:
app_label
=
'gis'
db_table
=
'spatial_ref_sys'
managed
=
False
@property
def
wkt
(
self
):
return
self
.
srtext
django/contrib/sites/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -84,6 +84,7 @@ class Site(models.Model):
unique
=
True
,
)
name
=
models
.
CharField
(
_
(
'display name'
),
max_length
=
50
)
objects
=
SiteManager
()
class
Meta
:
...
...
docs/topics/db/examples/many_to_many.txt
Dosyayı görüntüle @
e817ae74
...
...
@@ -17,22 +17,22 @@ objects, and a ``Publication`` has multiple ``Article`` objects:
class Publication(models.Model):
title = models.CharField(max_length=30)
def __str__(self):
return self.title
class Meta:
ordering = ('title',)
def __str__(self):
return self.title
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)
def __str__(self):
return self.headline
class Meta:
ordering = ('headline',)
def __str__(self):
return self.headline
What follows are examples of operations that can be performed using the Python
API facilities. Note that if you are using :ref:`an intermediate model
<intermediary-manytomany>` for a many-to-many relationship, some of the related
...
...
docs/topics/serialization.txt
Dosyayı görüntüle @
e817ae74
...
...
@@ -404,13 +404,12 @@ name::
return self.get(first_name=first_name, last_name=last_name)
class Person(models.Model):
objects = PersonManager()
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
birthdate = models.DateField()
objects = PersonManager()
class Meta:
unique_together = (('first_name', 'last_name'),)
...
...
@@ -453,19 +452,18 @@ So how do you get Django to emit a natural key when serializing an object?
Firstly, you need to add another method -- this time to the model itself::
class Person(models.Model):
objects = PersonManager()
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
birthdate = models.DateField()
def natural_key(self):
return (self.first_name, self.last_name)
objects = PersonManager()
class Meta:
unique_together = (('first_name', 'last_name'),)
def natural_key(self):
return (self.first_name, self.last_name)
That method should always return a natural key tuple -- in this
example, ``(first name, last name)``. Then, when you call
``serializers.serialize()``, you provide ``use_natural_foreign_keys=True``
...
...
tests/admin_views/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -80,13 +80,13 @@ class Chapter(models.Model):
content
=
models
.
TextField
()
book
=
models
.
ForeignKey
(
Book
,
models
.
CASCADE
)
def
__str__
(
self
):
return
self
.
title
class
Meta
:
# Use a utf-8 bytestring to ensure it works (see #11710)
verbose_name
=
'¿Chapter?'
def
__str__
(
self
):
return
self
.
title
class
ChapterXtra1
(
models
.
Model
):
chap
=
models
.
OneToOneField
(
Chapter
,
models
.
CASCADE
,
verbose_name
=
'¿Chap?'
)
...
...
tests/admin_widgets/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -135,12 +135,12 @@ class Advisor(models.Model):
class
Student
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
255
)
def
__str__
(
self
):
return
self
.
name
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
class
School
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
255
)
...
...
tests/custom_columns/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -23,13 +23,13 @@ class Author(models.Model):
first_name
=
models
.
CharField
(
max_length
=
30
,
db_column
=
'firstname'
)
last_name
=
models
.
CharField
(
max_length
=
30
,
db_column
=
'last'
)
def
__str__
(
self
):
return
'
%
s
%
s'
%
(
self
.
first_name
,
self
.
last_name
)
class
Meta
:
db_table
=
'my_author_table'
ordering
=
(
'last_name'
,
'first_name'
)
def
__str__
(
self
):
return
'
%
s
%
s'
%
(
self
.
first_name
,
self
.
last_name
)
class
Article
(
models
.
Model
):
Article_ID
=
models
.
AutoField
(
primary_key
=
True
,
db_column
=
'Article ID'
)
...
...
@@ -43,8 +43,8 @@ class Article(models.Model):
null
=
True
,
)
def
__str__
(
self
):
return
self
.
headline
class
Meta
:
ordering
=
(
'headline'
,)
def
__str__
(
self
):
return
self
.
headline
tests/fixtures/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -20,23 +20,23 @@ class Category(models.Model):
title
=
models
.
CharField
(
max_length
=
100
)
description
=
models
.
TextField
()
def
__str__
(
self
):
return
self
.
title
class
Meta
:
ordering
=
(
'title'
,)
def
__str__
(
self
):
return
self
.
title
class
Article
(
models
.
Model
):
headline
=
models
.
CharField
(
max_length
=
100
,
default
=
'Default headline'
)
pub_date
=
models
.
DateTimeField
()
def
__str__
(
self
):
return
self
.
headline
class
Meta
:
ordering
=
(
'-pub_date'
,
'headline'
)
def
__str__
(
self
):
return
self
.
headline
class
Blog
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
...
...
@@ -68,12 +68,12 @@ class Person(models.Model):
objects
=
PersonManager
()
name
=
models
.
CharField
(
max_length
=
100
)
def
__str__
(
self
):
return
self
.
name
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
def
natural_key
(
self
):
return
(
self
.
name
,)
...
...
@@ -106,13 +106,13 @@ class Book(models.Model):
name
=
models
.
CharField
(
max_length
=
100
)
authors
=
models
.
ManyToManyField
(
Person
)
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
authors
=
' and '
.
join
(
a
.
name
for
a
in
self
.
authors
.
all
())
return
'
%
s by
%
s'
%
(
self
.
name
,
authors
)
if
authors
else
self
.
name
class
Meta
:
ordering
=
(
'name'
,)
class
PrimaryKeyUUIDModel
(
models
.
Model
):
id
=
models
.
UUIDField
(
primary_key
=
True
,
default
=
uuid
.
uuid4
)
...
...
tests/fixtures_model_package/models/__init__.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -5,9 +5,9 @@ class Article(models.Model):
headline
=
models
.
CharField
(
max_length
=
100
,
default
=
'Default headline'
)
pub_date
=
models
.
DateTimeField
()
def
__str__
(
self
):
return
self
.
headline
class
Meta
:
app_label
=
'fixtures_model_package'
ordering
=
(
'-pub_date'
,
'headline'
)
def
__str__
(
self
):
return
self
.
headline
tests/fixtures_regress/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -98,10 +98,11 @@ class TestManager(models.Manager):
class
Store
(
models
.
Model
):
objects
=
TestManager
()
name
=
models
.
CharField
(
max_length
=
255
)
main
=
models
.
ForeignKey
(
'self'
,
models
.
SET_NULL
,
null
=
True
)
objects
=
TestManager
()
class
Meta
:
ordering
=
(
'name'
,)
...
...
@@ -113,9 +114,10 @@ class Store(models.Model):
class
Person
(
models
.
Model
):
objects
=
TestManager
()
name
=
models
.
CharField
(
max_length
=
255
)
objects
=
TestManager
()
class
Meta
:
ordering
=
(
'name'
,)
...
...
@@ -245,6 +247,7 @@ class BaseNKModel(models.Model):
Base model with a natural_key and a manager with `get_by_natural_key`
"""
data
=
models
.
CharField
(
max_length
=
20
,
unique
=
True
)
objects
=
NKManager
()
class
Meta
:
...
...
tests/introspection/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -41,9 +41,6 @@ class Article(models.Model):
response_to
=
models
.
ForeignKey
(
'self'
,
models
.
SET_NULL
,
null
=
True
)
unmanaged_reporters
=
models
.
ManyToManyField
(
Reporter
,
through
=
'ArticleReporter'
,
related_name
=
'+'
)
def
__str__
(
self
):
return
self
.
headline
class
Meta
:
ordering
=
(
'headline'
,)
index_together
=
[
...
...
@@ -51,6 +48,9 @@ class Article(models.Model):
[
'headline'
,
'response_to'
,
'pub_date'
,
'reporter'
],
]
def
__str__
(
self
):
return
self
.
headline
class
ArticleReporter
(
models
.
Model
):
article
=
models
.
ForeignKey
(
Article
,
models
.
CASCADE
)
...
...
tests/m2m_and_m2o/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -15,12 +15,12 @@ class Issue(models.Model):
cc
=
models
.
ManyToManyField
(
User
,
blank
=
True
,
related_name
=
'test_issue_cc'
)
client
=
models
.
ForeignKey
(
User
,
models
.
CASCADE
,
related_name
=
'test_issue_client'
)
def
__str__
(
self
):
return
str
(
self
.
num
)
class
Meta
:
ordering
=
(
'num'
,)
def
__str__
(
self
):
return
str
(
self
.
num
)
class
StringReferenceModel
(
models
.
Model
):
others
=
models
.
ManyToManyField
(
'StringReferenceModel'
)
tests/m2m_regress/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -73,12 +73,12 @@ class User(models.Model):
class
BadModelWithSplit
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
1
)
def
split
(
self
):
raise
RuntimeError
(
'split should not be called'
)
class
Meta
:
abstract
=
True
def
split
(
self
):
raise
RuntimeError
(
'split should not be called'
)
class
RegressionModelSplit
(
BadModelWithSplit
):
"""
...
...
tests/m2m_through/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -55,13 +55,13 @@ class CustomMembership(models.Model):
weird_fk
=
models
.
ForeignKey
(
Membership
,
models
.
SET_NULL
,
null
=
True
)
date_joined
=
models
.
DateTimeField
(
default
=
datetime
.
now
)
def
__str__
(
self
):
return
"
%
s is a member of
%
s"
%
(
self
.
person
.
name
,
self
.
group
.
name
)
class
Meta
:
db_table
=
"test_table"
ordering
=
[
"date_joined"
]
def
__str__
(
self
):
return
"
%
s is a member of
%
s"
%
(
self
.
person
.
name
,
self
.
group
.
name
)
class
TestNoDefaultsOrNulls
(
models
.
Model
):
person
=
models
.
ForeignKey
(
Person
,
models
.
CASCADE
)
...
...
tests/m2m_through_regress/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -52,12 +52,12 @@ class Car(models.Model):
class
Driver
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
,
unique
=
True
,
null
=
True
)
def
__str__
(
self
):
return
"
%
s"
%
self
.
name
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
"
%
s"
%
self
.
name
class
CarDriver
(
models
.
Model
):
car
=
models
.
ForeignKey
(
'Car'
,
models
.
CASCADE
,
to_field
=
'make'
)
...
...
tests/many_to_many/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -12,12 +12,12 @@ from django.db import models
class
Publication
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
30
)
def
__str__
(
self
):
return
self
.
title
class
Meta
:
ordering
=
(
'title'
,)
def
__str__
(
self
):
return
self
.
title
class
Tag
(
models
.
Model
):
id
=
models
.
BigAutoField
(
primary_key
=
True
)
...
...
@@ -34,12 +34,12 @@ class Article(models.Model):
publications
=
models
.
ManyToManyField
(
Publication
,
name
=
'publications'
)
tags
=
models
.
ManyToManyField
(
Tag
,
related_name
=
'tags'
)
def
__str__
(
self
):
return
self
.
headline
class
Meta
:
ordering
=
(
'headline'
,)
def
__str__
(
self
):
return
self
.
headline
# Models to test correct related_name inheritance
class
AbstractArticle
(
models
.
Model
):
...
...
tests/many_to_one/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -20,12 +20,12 @@ class Article(models.Model):
pub_date
=
models
.
DateField
()
reporter
=
models
.
ForeignKey
(
Reporter
,
models
.
CASCADE
)
def
__str__
(
self
):
return
self
.
headline
class
Meta
:
ordering
=
(
'headline'
,)
def
__str__
(
self
):
return
self
.
headline
class
City
(
models
.
Model
):
id
=
models
.
BigAutoField
(
primary_key
=
True
)
...
...
tests/model_forms/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -215,12 +215,12 @@ class Price(models.Model):
price
=
models
.
DecimalField
(
max_digits
=
10
,
decimal_places
=
2
)
quantity
=
models
.
PositiveIntegerField
()
def
__str__
(
self
):
return
"
%
s for
%
s"
%
(
self
.
quantity
,
self
.
price
)
class
Meta
:
unique_together
=
((
'price'
,
'quantity'
),)
def
__str__
(
self
):
return
"
%
s for
%
s"
%
(
self
.
quantity
,
self
.
price
)
class
Triple
(
models
.
Model
):
left
=
models
.
IntegerField
()
...
...
tests/model_formsets/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -135,12 +135,12 @@ class Price(models.Model):
price
=
models
.
DecimalField
(
max_digits
=
10
,
decimal_places
=
2
)
quantity
=
models
.
PositiveIntegerField
()
def
__str__
(
self
):
return
"
%
s for
%
s"
%
(
self
.
quantity
,
self
.
price
)
class
Meta
:
unique_together
=
((
'price'
,
'quantity'
),)
def
__str__
(
self
):
return
"
%
s for
%
s"
%
(
self
.
quantity
,
self
.
price
)
class
MexicanRestaurant
(
Restaurant
):
serves_tacos
=
models
.
BooleanField
(
default
=
False
)
...
...
tests/multiple_database/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -12,12 +12,12 @@ class Review(models.Model):
object_id
=
models
.
PositiveIntegerField
()
content_object
=
GenericForeignKey
()
def
__str__
(
self
):
return
self
.
source
class
Meta
:
ordering
=
(
'source'
,)
def
__str__
(
self
):
return
self
.
source
class
PersonManager
(
models
.
Manager
):
def
get_by_natural_key
(
self
,
name
):
...
...
@@ -25,15 +25,16 @@ class PersonManager(models.Manager):
class
Person
(
models
.
Model
):
objects
=
PersonManager
()
name
=
models
.
CharField
(
max_length
=
100
)
def
__str__
(
self
):
return
self
.
name
objects
=
PersonManager
()
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
# This book manager doesn't do anything interesting; it just
# exists to strip out the 'extra_arg' argument to certain
...
...
@@ -48,7 +49,6 @@ class BookManager(models.Manager):
class
Book
(
models
.
Model
):
objects
=
BookManager
()
title
=
models
.
CharField
(
max_length
=
100
)
published
=
models
.
DateField
()
authors
=
models
.
ManyToManyField
(
Person
)
...
...
@@ -56,23 +56,25 @@ class Book(models.Model):
reviews
=
GenericRelation
(
Review
)
pages
=
models
.
IntegerField
(
default
=
100
)
def
__str__
(
self
):
return
self
.
title
objects
=
BookManager
()
class
Meta
:
ordering
=
(
'title'
,)
def
__str__
(
self
):
return
self
.
title
class
Pet
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
owner
=
models
.
ForeignKey
(
Person
,
models
.
CASCADE
)
def
__str__
(
self
):
return
self
.
name
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
self
.
name
class
UserProfile
(
models
.
Model
):
user
=
models
.
OneToOneField
(
User
,
models
.
SET_NULL
,
null
=
True
)
...
...
tests/null_fk_ordering/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -17,12 +17,12 @@ class Article(models.Model):
title
=
models
.
CharField
(
max_length
=
150
)
author
=
models
.
ForeignKey
(
Author
,
models
.
SET_NULL
,
null
=
True
)
def
__str__
(
self
):
return
'Article titled:
%
s'
%
self
.
title
class
Meta
:
ordering
=
[
'author__name'
]
def
__str__
(
self
):
return
'Article titled:
%
s'
%
self
.
title
# These following 4 models represent a far more complex ordering case.
class
SystemInfo
(
models
.
Model
):
...
...
tests/prefetch_related/models.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -15,12 +15,12 @@ class Author(models.Model):
favorite_authors
=
models
.
ManyToManyField
(
'self'
,
through
=
'FavoriteAuthors'
,
symmetrical
=
False
,
related_name
=
'favors_me'
)
def
__str__
(
self
):
return
self
.
name
class
Meta
:
ordering
=
[
'id'
]
def
__str__
(
self
):
return
self
.
name
class
AuthorWithAge
(
Author
):
author
=
models
.
OneToOneField
(
Author
,
models
.
CASCADE
,
parent_link
=
True
)
...
...
@@ -50,12 +50,12 @@ class Book(models.Model):
title
=
models
.
CharField
(
max_length
=
255
)
authors
=
models
.
ManyToManyField
(
Author
,
related_name
=
'books'
)
def
__str__
(
self
):
return
self
.
title
class
Meta
:
ordering
=
[
'id'
]
def
__str__
(
self
):
return
self
.
title
class
BookWithYear
(
Book
):
book
=
models
.
OneToOneField
(
Book
,
models
.
CASCADE
,
parent_link
=
True
)
...
...
@@ -78,12 +78,12 @@ class Reader(models.Model):
name
=
models
.
CharField
(
max_length
=
50
)
books_read
=
models
.
ManyToManyField
(
Book
,
related_name
=
'read_by'
)
def
__str__
(
self
):
return
self
.
name
class
Meta
:
ordering
=
[
'id'
]
def
__str__
(
self
):
return
self
.
name
class
BookReview
(
models
.
Model
):
# Intentionally does not have a related name.
...
...
@@ -122,12 +122,12 @@ class Teacher(models.Model):
objects
=
TeacherManager
()
objects_custom
=
TeacherQuerySet
.
as_manager
()
def
__str__
(
self
):
return
"
%
s (
%
s)"
%
(
self
.
name
,
", "
.
join
(
q
.
name
for
q
in
self
.
qualifications
.
all
()))
class
Meta
:
ordering
=
[
'id'
]
def
__str__
(
self
):
return
"
%
s (
%
s)"
%
(
self
.
name
,
", "
.
join
(
q
.
name
for
q
in
self
.
qualifications
.
all
()))
class
Department
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
...
...
@@ -165,12 +165,12 @@ class TaggedItem(models.Model):
favorite_fkey
=
models
.
CharField
(
max_length
=
64
,
null
=
True
)
favorite
=
GenericForeignKey
(
'favorite_ct'
,
'favorite_fkey'
)
def
__str__
(
self
):
return
self
.
tag
class
Meta
:
ordering
=
[
'id'
]
def
__str__
(
self
):
return
self
.
tag
class
Bookmark
(
models
.
Model
):
url
=
models
.
URLField
()
...
...
@@ -243,12 +243,12 @@ class Employee(models.Model):
name
=
models
.
CharField
(
max_length
=
50
)
boss
=
models
.
ForeignKey
(
'self'
,
models
.
SET_NULL
,
null
=
True
,
related_name
=
'serfs'
)
def
__str__
(
self
):
return
self
.
name
class
Meta
:
ordering
=
[
'id'
]
def
__str__
(
self
):
return
self
.
name
# Ticket #19607
...
...
@@ -275,12 +275,12 @@ class Author2(models.Model):
first_book
=
models
.
ForeignKey
(
'Book'
,
models
.
CASCADE
,
related_name
=
'first_time_authors+'
)
favorite_books
=
models
.
ManyToManyField
(
'Book'
,
related_name
=
'+'
)
def
__str__
(
self
):
return
self
.
name
class
Meta
:
ordering
=
[
'id'
]
def
__str__
(
self
):
return
self
.
name
# Models for many-to-many with UUID pk test:
...
...
tests/serializers/models/natural.py
Dosyayı görüntüle @
e817ae74
...
...
@@ -10,11 +10,11 @@ class NaturalKeyAnchorManager(models.Manager):
class
NaturalKeyAnchor
(
models
.
Model
):
objects
=
NaturalKeyAnchorManager
()
data
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
)
title
=
models
.
CharField
(
max_length
=
100
,
null
=
True
)
objects
=
NaturalKeyAnchorManager
()
def
natural_key
(
self
):
return
(
self
.
data
,)
...
...
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