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
3f115776
Kaydet (Commit)
3f115776
authored
Kas 02, 2013
tarafından
Jason Myers
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
PEP8
Signed-off-by:
Jason Myers
<
jason@jasonamyers.com
>
üst
8eec2d93
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
172 additions
and
5 deletions
+172
-5
admin.py
tests/admin_views/admin.py
+22
-0
tests.py
tests/decorators/tests.py
+2
-1
models.py
tests/defer/models.py
+4
-0
models.py
tests/defer_regress/models.py
+14
-0
tests.py
tests/model_forms/tests.py
+8
-3
models.py
tests/model_forms_regress/models.py
+12
-0
tests.py
tests/model_forms_regress/tests.py
+6
-1
models.py
tests/model_formsets/models.py
+26
-0
models.py
tests/model_formsets_regress/models.py
+6
-0
tests.py
tests/model_formsets_regress/tests.py
+1
-0
models.py
tests/model_inheritance/models.py
+22
-0
models.py
tests/model_inheritance_regress/models.py
+37
-0
models.py
tests/model_inheritance_select_related/models.py
+2
-0
models.py
tests/model_validation/models.py
+1
-0
models.py
tests/modeladmin/models.py
+3
-0
models.py
tests/multiple_database/models.py
+6
-0
No files found.
tests/admin_views/admin.py
Dosyayı görüntüle @
3f115776
...
@@ -58,6 +58,7 @@ class ArticleInline(admin.TabularInline):
...
@@ -58,6 +58,7 @@ class ArticleInline(admin.TabularInline):
})
})
)
)
class
ChapterInline
(
admin
.
TabularInline
):
class
ChapterInline
(
admin
.
TabularInline
):
model
=
Chapter
model
=
Chapter
...
@@ -578,10 +579,12 @@ class AdminOrderedFieldAdmin(admin.ModelAdmin):
...
@@ -578,10 +579,12 @@ class AdminOrderedFieldAdmin(admin.ModelAdmin):
ordering
=
(
'order'
,)
ordering
=
(
'order'
,)
list_display
=
(
'stuff'
,
'order'
)
list_display
=
(
'stuff'
,
'order'
)
class
AdminOrderedModelMethodAdmin
(
admin
.
ModelAdmin
):
class
AdminOrderedModelMethodAdmin
(
admin
.
ModelAdmin
):
ordering
=
(
'order'
,)
ordering
=
(
'order'
,)
list_display
=
(
'stuff'
,
'some_order'
)
list_display
=
(
'stuff'
,
'some_order'
)
class
AdminOrderedAdminMethodAdmin
(
admin
.
ModelAdmin
):
class
AdminOrderedAdminMethodAdmin
(
admin
.
ModelAdmin
):
def
some_admin_order
(
self
,
obj
):
def
some_admin_order
(
self
,
obj
):
return
obj
.
order
return
obj
.
order
...
@@ -589,13 +592,17 @@ class AdminOrderedAdminMethodAdmin(admin.ModelAdmin):
...
@@ -589,13 +592,17 @@ class AdminOrderedAdminMethodAdmin(admin.ModelAdmin):
ordering
=
(
'order'
,)
ordering
=
(
'order'
,)
list_display
=
(
'stuff'
,
'some_admin_order'
)
list_display
=
(
'stuff'
,
'some_admin_order'
)
def
admin_ordered_callable
(
obj
):
def
admin_ordered_callable
(
obj
):
return
obj
.
order
return
obj
.
order
admin_ordered_callable
.
admin_order_field
=
'order'
admin_ordered_callable
.
admin_order_field
=
'order'
class
AdminOrderedCallableAdmin
(
admin
.
ModelAdmin
):
class
AdminOrderedCallableAdmin
(
admin
.
ModelAdmin
):
ordering
=
(
'order'
,)
ordering
=
(
'order'
,)
list_display
=
(
'stuff'
,
admin_ordered_callable
)
list_display
=
(
'stuff'
,
admin_ordered_callable
)
class
ReportAdmin
(
admin
.
ModelAdmin
):
class
ReportAdmin
(
admin
.
ModelAdmin
):
def
extra
(
self
,
request
):
def
extra
(
self
,
request
):
return
HttpResponse
()
return
HttpResponse
()
...
@@ -612,6 +619,7 @@ class ReportAdmin(admin.ModelAdmin):
...
@@ -612,6 +619,7 @@ class ReportAdmin(admin.ModelAdmin):
class
CustomTemplateBooleanFieldListFilter
(
BooleanFieldListFilter
):
class
CustomTemplateBooleanFieldListFilter
(
BooleanFieldListFilter
):
template
=
'custom_filter_template.html'
template
=
'custom_filter_template.html'
class
CustomTemplateFilterColorAdmin
(
admin
.
ModelAdmin
):
class
CustomTemplateFilterColorAdmin
(
admin
.
ModelAdmin
):
list_filter
=
((
'warm'
,
CustomTemplateBooleanFieldListFilter
),)
list_filter
=
((
'warm'
,
CustomTemplateBooleanFieldListFilter
),)
...
@@ -628,12 +636,14 @@ class RelatedPrepopulatedInline1(admin.StackedInline):
...
@@ -628,12 +636,14 @@ class RelatedPrepopulatedInline1(admin.StackedInline):
prepopulated_fields
=
{
'slug1'
:
[
'name'
,
'pubdate'
],
prepopulated_fields
=
{
'slug1'
:
[
'name'
,
'pubdate'
],
'slug2'
:
[
'status'
,
'name'
]}
'slug2'
:
[
'status'
,
'name'
]}
class
RelatedPrepopulatedInline2
(
admin
.
TabularInline
):
class
RelatedPrepopulatedInline2
(
admin
.
TabularInline
):
model
=
RelatedPrepopulated
model
=
RelatedPrepopulated
extra
=
1
extra
=
1
prepopulated_fields
=
{
'slug1'
:
[
'name'
,
'pubdate'
],
prepopulated_fields
=
{
'slug1'
:
[
'name'
,
'pubdate'
],
'slug2'
:
[
'status'
,
'name'
]}
'slug2'
:
[
'status'
,
'name'
]}
class
MainPrepopulatedAdmin
(
admin
.
ModelAdmin
):
class
MainPrepopulatedAdmin
(
admin
.
ModelAdmin
):
inlines
=
[
RelatedPrepopulatedInline1
,
RelatedPrepopulatedInline2
]
inlines
=
[
RelatedPrepopulatedInline1
,
RelatedPrepopulatedInline2
]
fieldsets
=
(
fieldsets
=
(
...
@@ -712,14 +722,17 @@ class FormWithoutHiddenField(forms.ModelForm):
...
@@ -712,14 +722,17 @@ class FormWithoutHiddenField(forms.ModelForm):
first
=
forms
.
CharField
()
first
=
forms
.
CharField
()
second
=
forms
.
CharField
()
second
=
forms
.
CharField
()
class
FormWithoutVisibleField
(
forms
.
ModelForm
):
class
FormWithoutVisibleField
(
forms
.
ModelForm
):
first
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
)
first
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
)
second
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
)
second
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
)
class
FormWithVisibleAndHiddenField
(
forms
.
ModelForm
):
class
FormWithVisibleAndHiddenField
(
forms
.
ModelForm
):
first
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
)
first
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
)
second
=
forms
.
CharField
()
second
=
forms
.
CharField
()
class
EmptyModelVisibleAdmin
(
admin
.
ModelAdmin
):
class
EmptyModelVisibleAdmin
(
admin
.
ModelAdmin
):
form
=
FormWithoutHiddenField
form
=
FormWithoutHiddenField
fieldsets
=
(
fieldsets
=
(
...
@@ -728,39 +741,48 @@ class EmptyModelVisibleAdmin(admin.ModelAdmin):
...
@@ -728,39 +741,48 @@ class EmptyModelVisibleAdmin(admin.ModelAdmin):
}),
}),
)
)
class
EmptyModelHiddenAdmin
(
admin
.
ModelAdmin
):
class
EmptyModelHiddenAdmin
(
admin
.
ModelAdmin
):
form
=
FormWithoutVisibleField
form
=
FormWithoutVisibleField
fieldsets
=
EmptyModelVisibleAdmin
.
fieldsets
fieldsets
=
EmptyModelVisibleAdmin
.
fieldsets
class
EmptyModelMixinAdmin
(
admin
.
ModelAdmin
):
class
EmptyModelMixinAdmin
(
admin
.
ModelAdmin
):
form
=
FormWithVisibleAndHiddenField
form
=
FormWithVisibleAndHiddenField
fieldsets
=
EmptyModelVisibleAdmin
.
fieldsets
fieldsets
=
EmptyModelVisibleAdmin
.
fieldsets
class
CityInlineAdmin
(
admin
.
TabularInline
):
class
CityInlineAdmin
(
admin
.
TabularInline
):
model
=
City
model
=
City
view_on_site
=
False
view_on_site
=
False
class
StateAdmin
(
admin
.
ModelAdmin
):
class
StateAdmin
(
admin
.
ModelAdmin
):
inlines
=
[
CityInlineAdmin
]
inlines
=
[
CityInlineAdmin
]
class
RestaurantInlineAdmin
(
admin
.
TabularInline
):
class
RestaurantInlineAdmin
(
admin
.
TabularInline
):
model
=
Restaurant
model
=
Restaurant
view_on_site
=
True
view_on_site
=
True
class
CityAdmin
(
admin
.
ModelAdmin
):
class
CityAdmin
(
admin
.
ModelAdmin
):
inlines
=
[
RestaurantInlineAdmin
]
inlines
=
[
RestaurantInlineAdmin
]
view_on_site
=
True
view_on_site
=
True
class
WorkerAdmin
(
admin
.
ModelAdmin
):
class
WorkerAdmin
(
admin
.
ModelAdmin
):
def
view_on_site
(
self
,
obj
):
def
view_on_site
(
self
,
obj
):
return
'/worker/
%
s/
%
s/'
%
(
obj
.
surname
,
obj
.
name
)
return
'/worker/
%
s/
%
s/'
%
(
obj
.
surname
,
obj
.
name
)
class
WorkerInlineAdmin
(
admin
.
TabularInline
):
class
WorkerInlineAdmin
(
admin
.
TabularInline
):
model
=
Worker
model
=
Worker
def
view_on_site
(
self
,
obj
):
def
view_on_site
(
self
,
obj
):
return
'/worker_inline/
%
s/
%
s/'
%
(
obj
.
surname
,
obj
.
name
)
return
'/worker_inline/
%
s/
%
s/'
%
(
obj
.
surname
,
obj
.
name
)
class
RestaurantAdmin
(
admin
.
ModelAdmin
):
class
RestaurantAdmin
(
admin
.
ModelAdmin
):
inlines
=
[
WorkerInlineAdmin
]
inlines
=
[
WorkerInlineAdmin
]
view_on_site
=
False
view_on_site
=
False
...
...
tests/decorators/tests.py
Dosyayı görüntüle @
3f115776
...
@@ -44,7 +44,7 @@ full_decorator = compose(
...
@@ -44,7 +44,7 @@ full_decorator = compose(
vary_on_cookie
,
vary_on_cookie
,
# django.views.decorators.cache
# django.views.decorators.cache
cache_page
(
60
*
15
),
cache_page
(
60
*
15
),
cache_control
(
private
=
True
),
cache_control
(
private
=
True
),
never_cache
,
never_cache
,
...
@@ -65,6 +65,7 @@ full_decorator = compose(
...
@@ -65,6 +65,7 @@ full_decorator = compose(
fully_decorated
=
full_decorator
(
fully_decorated
)
fully_decorated
=
full_decorator
(
fully_decorated
)
class
DecoratorsTest
(
TestCase
):
class
DecoratorsTest
(
TestCase
):
def
test_attributes
(
self
):
def
test_attributes
(
self
):
...
...
tests/defer/models.py
Dosyayı görüntüle @
3f115776
...
@@ -10,6 +10,7 @@ class Secondary(models.Model):
...
@@ -10,6 +10,7 @@ class Secondary(models.Model):
first
=
models
.
CharField
(
max_length
=
50
)
first
=
models
.
CharField
(
max_length
=
50
)
second
=
models
.
CharField
(
max_length
=
50
)
second
=
models
.
CharField
(
max_length
=
50
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Primary
(
models
.
Model
):
class
Primary
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
...
@@ -19,12 +20,15 @@ class Primary(models.Model):
...
@@ -19,12 +20,15 @@ class Primary(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
class
Child
(
Primary
):
class
Child
(
Primary
):
pass
pass
class
BigChild
(
Primary
):
class
BigChild
(
Primary
):
other
=
models
.
CharField
(
max_length
=
50
)
other
=
models
.
CharField
(
max_length
=
50
)
class
ChildProxy
(
Child
):
class
ChildProxy
(
Child
):
class
Meta
:
class
Meta
:
proxy
=
True
proxy
=
True
tests/defer_regress/models.py
Dosyayı görüntüle @
3f115776
...
@@ -16,13 +16,16 @@ class Item(models.Model):
...
@@ -16,13 +16,16 @@ class Item(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
class
RelatedItem
(
models
.
Model
):
class
RelatedItem
(
models
.
Model
):
item
=
models
.
ForeignKey
(
Item
)
item
=
models
.
ForeignKey
(
Item
)
class
Child
(
models
.
Model
):
class
Child
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
10
)
name
=
models
.
CharField
(
max_length
=
10
)
value
=
models
.
IntegerField
()
value
=
models
.
IntegerField
()
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Leaf
(
models
.
Model
):
class
Leaf
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
10
)
name
=
models
.
CharField
(
max_length
=
10
)
...
@@ -33,14 +36,17 @@ class Leaf(models.Model):
...
@@ -33,14 +36,17 @@ class Leaf(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
class
ResolveThis
(
models
.
Model
):
class
ResolveThis
(
models
.
Model
):
num
=
models
.
FloatField
()
num
=
models
.
FloatField
()
name
=
models
.
CharField
(
max_length
=
16
)
name
=
models
.
CharField
(
max_length
=
16
)
class
Proxy
(
Item
):
class
Proxy
(
Item
):
class
Meta
:
class
Meta
:
proxy
=
True
proxy
=
True
@python_2_unicode_compatible
@python_2_unicode_compatible
class
SimpleItem
(
models
.
Model
):
class
SimpleItem
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
15
)
name
=
models
.
CharField
(
max_length
=
15
)
...
@@ -49,29 +55,37 @@ class SimpleItem(models.Model):
...
@@ -49,29 +55,37 @@ class SimpleItem(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
class
Feature
(
models
.
Model
):
class
Feature
(
models
.
Model
):
item
=
models
.
ForeignKey
(
SimpleItem
)
item
=
models
.
ForeignKey
(
SimpleItem
)
class
SpecialFeature
(
models
.
Model
):
class
SpecialFeature
(
models
.
Model
):
feature
=
models
.
ForeignKey
(
Feature
)
feature
=
models
.
ForeignKey
(
Feature
)
class
OneToOneItem
(
models
.
Model
):
class
OneToOneItem
(
models
.
Model
):
item
=
models
.
OneToOneField
(
Item
,
related_name
=
"one_to_one_item"
)
item
=
models
.
OneToOneField
(
Item
,
related_name
=
"one_to_one_item"
)
name
=
models
.
CharField
(
max_length
=
15
)
name
=
models
.
CharField
(
max_length
=
15
)
class
ItemAndSimpleItem
(
models
.
Model
):
class
ItemAndSimpleItem
(
models
.
Model
):
item
=
models
.
ForeignKey
(
Item
)
item
=
models
.
ForeignKey
(
Item
)
simple
=
models
.
ForeignKey
(
SimpleItem
)
simple
=
models
.
ForeignKey
(
SimpleItem
)
class
Profile
(
models
.
Model
):
class
Profile
(
models
.
Model
):
profile1
=
models
.
CharField
(
max_length
=
1000
,
default
=
'profile1'
)
profile1
=
models
.
CharField
(
max_length
=
1000
,
default
=
'profile1'
)
class
Location
(
models
.
Model
):
class
Location
(
models
.
Model
):
location1
=
models
.
CharField
(
max_length
=
1000
,
default
=
'location1'
)
location1
=
models
.
CharField
(
max_length
=
1000
,
default
=
'location1'
)
class
Item
(
models
.
Model
):
class
Item
(
models
.
Model
):
pass
pass
class
Request
(
models
.
Model
):
class
Request
(
models
.
Model
):
profile
=
models
.
ForeignKey
(
Profile
,
null
=
True
,
blank
=
True
)
profile
=
models
.
ForeignKey
(
Profile
,
null
=
True
,
blank
=
True
)
location
=
models
.
ForeignKey
(
Location
)
location
=
models
.
ForeignKey
(
Location
)
...
...
tests/model_forms/tests.py
Dosyayı görüntüle @
3f115776
...
@@ -185,6 +185,7 @@ class BetterWriterForm(forms.ModelForm):
...
@@ -185,6 +185,7 @@ class BetterWriterForm(forms.ModelForm):
model
=
BetterWriter
model
=
BetterWriter
fields
=
'__all__'
fields
=
'__all__'
class
WriterProfileForm
(
forms
.
ModelForm
):
class
WriterProfileForm
(
forms
.
ModelForm
):
class
Meta
:
class
Meta
:
model
=
WriterProfile
model
=
WriterProfile
...
@@ -234,6 +235,7 @@ class ColourfulItemForm(forms.ModelForm):
...
@@ -234,6 +235,7 @@ class ColourfulItemForm(forms.ModelForm):
# model forms for testing work on #9321:
# model forms for testing work on #9321:
class
StatusNoteForm
(
forms
.
ModelForm
):
class
StatusNoteForm
(
forms
.
ModelForm
):
class
Meta
:
class
Meta
:
model
=
ArticleStatusNote
model
=
ArticleStatusNote
...
@@ -295,7 +297,7 @@ class ModelFormBaseTest(TestCase):
...
@@ -295,7 +297,7 @@ class ModelFormBaseTest(TestCase):
fields
=
'__all__'
fields
=
'__all__'
self
.
assertIsInstance
(
ReplaceField
.
base_fields
[
'url'
],
self
.
assertIsInstance
(
ReplaceField
.
base_fields
[
'url'
],
forms
.
fields
.
BooleanField
)
forms
.
fields
.
BooleanField
)
def
test_replace_field_variant_2
(
self
):
def
test_replace_field_variant_2
(
self
):
# Should have the same result as before,
# Should have the same result as before,
...
@@ -308,7 +310,7 @@ class ModelFormBaseTest(TestCase):
...
@@ -308,7 +310,7 @@ class ModelFormBaseTest(TestCase):
fields
=
[
'url'
]
fields
=
[
'url'
]
self
.
assertIsInstance
(
ReplaceField
.
base_fields
[
'url'
],
self
.
assertIsInstance
(
ReplaceField
.
base_fields
[
'url'
],
forms
.
fields
.
BooleanField
)
forms
.
fields
.
BooleanField
)
def
test_replace_field_variant_3
(
self
):
def
test_replace_field_variant_3
(
self
):
# Should have the same result as before,
# Should have the same result as before,
...
@@ -321,7 +323,7 @@ class ModelFormBaseTest(TestCase):
...
@@ -321,7 +323,7 @@ class ModelFormBaseTest(TestCase):
fields
=
[]
# url will still appear, since it is explicit above
fields
=
[]
# url will still appear, since it is explicit above
self
.
assertIsInstance
(
ReplaceField
.
base_fields
[
'url'
],
self
.
assertIsInstance
(
ReplaceField
.
base_fields
[
'url'
],
forms
.
fields
.
BooleanField
)
forms
.
fields
.
BooleanField
)
def
test_override_field
(
self
):
def
test_override_field
(
self
):
class
WriterForm
(
forms
.
ModelForm
):
class
WriterForm
(
forms
.
ModelForm
):
...
@@ -583,6 +585,7 @@ class IncompleteCategoryFormWithFields(forms.ModelForm):
...
@@ -583,6 +585,7 @@ class IncompleteCategoryFormWithFields(forms.ModelForm):
fields
=
(
'name'
,
'slug'
)
fields
=
(
'name'
,
'slug'
)
model
=
Category
model
=
Category
class
IncompleteCategoryFormWithExclude
(
forms
.
ModelForm
):
class
IncompleteCategoryFormWithExclude
(
forms
.
ModelForm
):
"""
"""
A form that replaces the model's url field with a custom one. This should
A form that replaces the model's url field with a custom one. This should
...
@@ -788,6 +791,7 @@ class UniqueTest(TestCase):
...
@@ -788,6 +791,7 @@ class UniqueTest(TestCase):
"slug"
:
"Django 1.0"
},
instance
=
p
)
"slug"
:
"Django 1.0"
},
instance
=
p
)
self
.
assertTrue
(
form
.
is_valid
())
self
.
assertTrue
(
form
.
is_valid
())
class
ModelToDictTests
(
TestCase
):
class
ModelToDictTests
(
TestCase
):
"""
"""
Tests for forms.models.model_to_dict
Tests for forms.models.model_to_dict
...
@@ -824,6 +828,7 @@ class ModelToDictTests(TestCase):
...
@@ -824,6 +828,7 @@ class ModelToDictTests(TestCase):
# Ensure many-to-many relation appears as a list
# Ensure many-to-many relation appears as a list
self
.
assertIsInstance
(
d
[
'categories'
],
list
)
self
.
assertIsInstance
(
d
[
'categories'
],
list
)
class
OldFormForXTests
(
TestCase
):
class
OldFormForXTests
(
TestCase
):
def
test_base_form
(
self
):
def
test_base_form
(
self
):
self
.
assertEqual
(
Category
.
objects
.
count
(),
0
)
self
.
assertEqual
(
Category
.
objects
.
count
(),
0
)
...
...
tests/model_forms_regress/models.py
Dosyayı görüntüle @
3f115776
...
@@ -11,6 +11,7 @@ from django.utils._os import upath
...
@@ -11,6 +11,7 @@ from django.utils._os import upath
class
Person
(
models
.
Model
):
class
Person
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
name
=
models
.
CharField
(
max_length
=
100
)
class
Triple
(
models
.
Model
):
class
Triple
(
models
.
Model
):
left
=
models
.
IntegerField
()
left
=
models
.
IntegerField
()
middle
=
models
.
IntegerField
()
middle
=
models
.
IntegerField
()
...
@@ -19,9 +20,11 @@ class Triple(models.Model):
...
@@ -19,9 +20,11 @@ class Triple(models.Model):
class
Meta
:
class
Meta
:
unique_together
=
((
'left'
,
'middle'
),
(
'middle'
,
'right'
))
unique_together
=
((
'left'
,
'middle'
),
(
'middle'
,
'right'
))
class
FilePathModel
(
models
.
Model
):
class
FilePathModel
(
models
.
Model
):
path
=
models
.
FilePathField
(
path
=
os
.
path
.
dirname
(
upath
(
__file__
)),
match
=
".*
\
.py$"
,
blank
=
True
)
path
=
models
.
FilePathField
(
path
=
os
.
path
.
dirname
(
upath
(
__file__
)),
match
=
".*
\
.py$"
,
blank
=
True
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Publication
(
models
.
Model
):
class
Publication
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
30
)
title
=
models
.
CharField
(
max_length
=
30
)
...
@@ -30,6 +33,7 @@ class Publication(models.Model):
...
@@ -30,6 +33,7 @@ class Publication(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
title
return
self
.
title
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Article
(
models
.
Model
):
class
Article
(
models
.
Model
):
headline
=
models
.
CharField
(
max_length
=
100
)
headline
=
models
.
CharField
(
max_length
=
100
)
...
@@ -38,15 +42,18 @@ class Article(models.Model):
...
@@ -38,15 +42,18 @@ class Article(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
headline
return
self
.
headline
class
CustomFileField
(
models
.
FileField
):
class
CustomFileField
(
models
.
FileField
):
def
save_form_data
(
self
,
instance
,
data
):
def
save_form_data
(
self
,
instance
,
data
):
been_here
=
getattr
(
self
,
'been_saved'
,
False
)
been_here
=
getattr
(
self
,
'been_saved'
,
False
)
assert
not
been_here
,
"save_form_data called more than once"
assert
not
been_here
,
"save_form_data called more than once"
setattr
(
self
,
'been_saved'
,
True
)
setattr
(
self
,
'been_saved'
,
True
)
class
CustomFF
(
models
.
Model
):
class
CustomFF
(
models
.
Model
):
f
=
CustomFileField
(
upload_to
=
'unused'
,
blank
=
True
)
f
=
CustomFileField
(
upload_to
=
'unused'
,
blank
=
True
)
class
RealPerson
(
models
.
Model
):
class
RealPerson
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
name
=
models
.
CharField
(
max_length
=
100
)
...
@@ -54,20 +61,25 @@ class RealPerson(models.Model):
...
@@ -54,20 +61,25 @@ class RealPerson(models.Model):
if
self
.
name
.
lower
()
==
'anonymous'
:
if
self
.
name
.
lower
()
==
'anonymous'
:
raise
ValidationError
(
"Please specify a real name."
)
raise
ValidationError
(
"Please specify a real name."
)
class
Author
(
models
.
Model
):
class
Author
(
models
.
Model
):
publication
=
models
.
OneToOneField
(
Publication
,
null
=
True
,
blank
=
True
)
publication
=
models
.
OneToOneField
(
Publication
,
null
=
True
,
blank
=
True
)
full_name
=
models
.
CharField
(
max_length
=
255
)
full_name
=
models
.
CharField
(
max_length
=
255
)
class
Author1
(
models
.
Model
):
class
Author1
(
models
.
Model
):
publication
=
models
.
OneToOneField
(
Publication
,
null
=
False
)
publication
=
models
.
OneToOneField
(
Publication
,
null
=
False
)
full_name
=
models
.
CharField
(
max_length
=
255
)
full_name
=
models
.
CharField
(
max_length
=
255
)
class
Homepage
(
models
.
Model
):
class
Homepage
(
models
.
Model
):
url
=
models
.
URLField
()
url
=
models
.
URLField
()
class
Document
(
models
.
Model
):
class
Document
(
models
.
Model
):
myfile
=
models
.
FileField
(
upload_to
=
'unused'
,
blank
=
True
)
myfile
=
models
.
FileField
(
upload_to
=
'unused'
,
blank
=
True
)
class
Edition
(
models
.
Model
):
class
Edition
(
models
.
Model
):
author
=
models
.
ForeignKey
(
Person
)
author
=
models
.
ForeignKey
(
Person
)
publication
=
models
.
ForeignKey
(
Publication
)
publication
=
models
.
ForeignKey
(
Publication
)
...
...
tests/model_forms_regress/tests.py
Dosyayı görüntüle @
3f115776
...
@@ -106,6 +106,7 @@ class FullyLocalizedTripleForm(forms.ModelForm):
...
@@ -106,6 +106,7 @@ class FullyLocalizedTripleForm(forms.ModelForm):
localized_fields
=
'__all__'
localized_fields
=
'__all__'
fields
=
'__all__'
fields
=
'__all__'
class
LocalizedModelFormTest
(
TestCase
):
class
LocalizedModelFormTest
(
TestCase
):
def
test_model_form_applies_localize_to_some_fields
(
self
):
def
test_model_form_applies_localize_to_some_fields
(
self
):
f
=
PartiallyLocalizedTripleForm
({
'left'
:
10
,
'middle'
:
10
,
'right'
:
10
})
f
=
PartiallyLocalizedTripleForm
({
'left'
:
10
,
'middle'
:
10
,
'right'
:
10
})
...
@@ -167,6 +168,7 @@ class FilePathFieldTests(TestCase):
...
@@ -167,6 +168,7 @@ class FilePathFieldTests(TestCase):
names
.
sort
()
names
.
sort
()
self
.
assertEqual
(
names
,
[
'---------'
,
'__init__.py'
,
'models.py'
,
'tests.py'
])
self
.
assertEqual
(
names
,
[
'---------'
,
'__init__.py'
,
'models.py'
,
'tests.py'
])
class
ManyToManyCallableInitialTests
(
TestCase
):
class
ManyToManyCallableInitialTests
(
TestCase
):
def
test_callable
(
self
):
def
test_callable
(
self
):
"Regression for #10349: A callable can be provided as the initial value for an m2m field"
"Regression for #10349: A callable can be provided as the initial value for an m2m field"
...
@@ -207,9 +209,10 @@ class CustomFieldSaveTests(TestCase):
...
@@ -207,9 +209,10 @@ class CustomFieldSaveTests(TestCase):
# It's enough that the form saves without error -- the custom save routine will
# It's enough that the form saves without error -- the custom save routine will
# generate an AssertionError if it is called more than once during save.
# generate an AssertionError if it is called more than once during save.
form
=
CFFForm
(
data
=
{
'f'
:
None
})
form
=
CFFForm
(
data
=
{
'f'
:
None
})
form
.
save
()
form
.
save
()
class
ModelChoiceIteratorTests
(
TestCase
):
class
ModelChoiceIteratorTests
(
TestCase
):
def
test_len
(
self
):
def
test_len
(
self
):
class
Form
(
forms
.
ModelForm
):
class
Form
(
forms
.
ModelForm
):
...
@@ -236,12 +239,14 @@ class CustomModelFormSaveMethod(TestCase):
...
@@ -236,12 +239,14 @@ class CustomModelFormSaveMethod(TestCase):
self
.
assertEqual
(
form
.
is_valid
(),
False
)
self
.
assertEqual
(
form
.
is_valid
(),
False
)
self
.
assertEqual
(
form
.
errors
[
'__all__'
],
[
'Please specify a real name.'
])
self
.
assertEqual
(
form
.
errors
[
'__all__'
],
[
'Please specify a real name.'
])
class
ModelClassTests
(
TestCase
):
class
ModelClassTests
(
TestCase
):
def
test_no_model_class
(
self
):
def
test_no_model_class
(
self
):
class
NoModelModelForm
(
forms
.
ModelForm
):
class
NoModelModelForm
(
forms
.
ModelForm
):
pass
pass
self
.
assertRaises
(
ValueError
,
NoModelModelForm
)
self
.
assertRaises
(
ValueError
,
NoModelModelForm
)
class
OneToOneFieldTests
(
TestCase
):
class
OneToOneFieldTests
(
TestCase
):
def
test_assignment_of_none
(
self
):
def
test_assignment_of_none
(
self
):
class
AuthorForm
(
forms
.
ModelForm
):
class
AuthorForm
(
forms
.
ModelForm
):
...
...
tests/model_formsets/models.py
Dosyayı görüntüle @
3f115776
...
@@ -17,9 +17,11 @@ class Author(models.Model):
...
@@ -17,9 +17,11 @@ class Author(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
class
BetterAuthor
(
Author
):
class
BetterAuthor
(
Author
):
write_speed
=
models
.
IntegerField
()
write_speed
=
models
.
IntegerField
()
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Book
(
models
.
Model
):
class
Book
(
models
.
Model
):
author
=
models
.
ForeignKey
(
Author
)
author
=
models
.
ForeignKey
(
Author
)
...
@@ -34,6 +36,7 @@ class Book(models.Model):
...
@@ -34,6 +36,7 @@ class Book(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
title
return
self
.
title
@python_2_unicode_compatible
@python_2_unicode_compatible
class
BookWithCustomPK
(
models
.
Model
):
class
BookWithCustomPK
(
models
.
Model
):
my_pk
=
models
.
DecimalField
(
max_digits
=
5
,
decimal_places
=
0
,
primary_key
=
True
)
my_pk
=
models
.
DecimalField
(
max_digits
=
5
,
decimal_places
=
0
,
primary_key
=
True
)
...
@@ -43,9 +46,11 @@ class BookWithCustomPK(models.Model):
...
@@ -43,9 +46,11 @@ class BookWithCustomPK(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
'
%
s:
%
s'
%
(
self
.
my_pk
,
self
.
title
)
return
'
%
s:
%
s'
%
(
self
.
my_pk
,
self
.
title
)
class
Editor
(
models
.
Model
):
class
Editor
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
name
=
models
.
CharField
(
max_length
=
100
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
BookWithOptionalAltEditor
(
models
.
Model
):
class
BookWithOptionalAltEditor
(
models
.
Model
):
author
=
models
.
ForeignKey
(
Author
)
author
=
models
.
ForeignKey
(
Author
)
...
@@ -61,6 +66,7 @@ class BookWithOptionalAltEditor(models.Model):
...
@@ -61,6 +66,7 @@ class BookWithOptionalAltEditor(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
title
return
self
.
title
@python_2_unicode_compatible
@python_2_unicode_compatible
class
AlternateBook
(
Book
):
class
AlternateBook
(
Book
):
notes
=
models
.
CharField
(
max_length
=
100
)
notes
=
models
.
CharField
(
max_length
=
100
)
...
@@ -68,6 +74,7 @@ class AlternateBook(Book):
...
@@ -68,6 +74,7 @@ class AlternateBook(Book):
def
__str__
(
self
):
def
__str__
(
self
):
return
'
%
s -
%
s'
%
(
self
.
title
,
self
.
notes
)
return
'
%
s -
%
s'
%
(
self
.
title
,
self
.
notes
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
AuthorMeeting
(
models
.
Model
):
class
AuthorMeeting
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
name
=
models
.
CharField
(
max_length
=
100
)
...
@@ -77,6 +84,7 @@ class AuthorMeeting(models.Model):
...
@@ -77,6 +84,7 @@ class AuthorMeeting(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
class
CustomPrimaryKey
(
models
.
Model
):
class
CustomPrimaryKey
(
models
.
Model
):
my_pk
=
models
.
CharField
(
max_length
=
10
,
primary_key
=
True
)
my_pk
=
models
.
CharField
(
max_length
=
10
,
primary_key
=
True
)
some_field
=
models
.
CharField
(
max_length
=
100
)
some_field
=
models
.
CharField
(
max_length
=
100
)
...
@@ -84,6 +92,7 @@ class CustomPrimaryKey(models.Model):
...
@@ -84,6 +92,7 @@ class CustomPrimaryKey(models.Model):
# models for inheritance tests.
# models for inheritance tests.
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Place
(
models
.
Model
):
class
Place
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
...
@@ -92,6 +101,7 @@ class Place(models.Model):
...
@@ -92,6 +101,7 @@ class Place(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Owner
(
models
.
Model
):
class
Owner
(
models
.
Model
):
auto_id
=
models
.
AutoField
(
primary_key
=
True
)
auto_id
=
models
.
AutoField
(
primary_key
=
True
)
...
@@ -101,12 +111,14 @@ class Owner(models.Model):
...
@@ -101,12 +111,14 @@ class Owner(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s at
%
s"
%
(
self
.
name
,
self
.
place
)
return
"
%
s at
%
s"
%
(
self
.
name
,
self
.
place
)
class
Location
(
models
.
Model
):
class
Location
(
models
.
Model
):
place
=
models
.
ForeignKey
(
Place
,
unique
=
True
)
place
=
models
.
ForeignKey
(
Place
,
unique
=
True
)
# this is purely for testing the data doesn't matter here :)
# this is purely for testing the data doesn't matter here :)
lat
=
models
.
CharField
(
max_length
=
100
)
lat
=
models
.
CharField
(
max_length
=
100
)
lon
=
models
.
CharField
(
max_length
=
100
)
lon
=
models
.
CharField
(
max_length
=
100
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
OwnerProfile
(
models
.
Model
):
class
OwnerProfile
(
models
.
Model
):
owner
=
models
.
OneToOneField
(
Owner
,
primary_key
=
True
)
owner
=
models
.
OneToOneField
(
Owner
,
primary_key
=
True
)
...
@@ -115,6 +127,7 @@ class OwnerProfile(models.Model):
...
@@ -115,6 +127,7 @@ class OwnerProfile(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s is
%
d"
%
(
self
.
owner
.
name
,
self
.
age
)
return
"
%
s is
%
d"
%
(
self
.
owner
.
name
,
self
.
age
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Restaurant
(
Place
):
class
Restaurant
(
Place
):
serves_pizza
=
models
.
BooleanField
(
default
=
False
)
serves_pizza
=
models
.
BooleanField
(
default
=
False
)
...
@@ -122,6 +135,7 @@ class Restaurant(Place):
...
@@ -122,6 +135,7 @@ class Restaurant(Place):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Product
(
models
.
Model
):
class
Product
(
models
.
Model
):
slug
=
models
.
SlugField
(
unique
=
True
)
slug
=
models
.
SlugField
(
unique
=
True
)
...
@@ -129,6 +143,7 @@ class Product(models.Model):
...
@@ -129,6 +143,7 @@ class Product(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
slug
return
self
.
slug
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Price
(
models
.
Model
):
class
Price
(
models
.
Model
):
price
=
models
.
DecimalField
(
max_digits
=
10
,
decimal_places
=
2
)
price
=
models
.
DecimalField
(
max_digits
=
10
,
decimal_places
=
2
)
...
@@ -140,13 +155,16 @@ class Price(models.Model):
...
@@ -140,13 +155,16 @@ class Price(models.Model):
class
Meta
:
class
Meta
:
unique_together
=
((
'price'
,
'quantity'
),)
unique_together
=
((
'price'
,
'quantity'
),)
class
MexicanRestaurant
(
Restaurant
):
class
MexicanRestaurant
(
Restaurant
):
serves_tacos
=
models
.
BooleanField
(
default
=
False
)
serves_tacos
=
models
.
BooleanField
(
default
=
False
)
class
ClassyMexicanRestaurant
(
MexicanRestaurant
):
class
ClassyMexicanRestaurant
(
MexicanRestaurant
):
restaurant
=
models
.
OneToOneField
(
MexicanRestaurant
,
parent_link
=
True
,
primary_key
=
True
)
restaurant
=
models
.
OneToOneField
(
MexicanRestaurant
,
parent_link
=
True
,
primary_key
=
True
)
tacos_are_yummy
=
models
.
BooleanField
(
default
=
False
)
tacos_are_yummy
=
models
.
BooleanField
(
default
=
False
)
# models for testing unique_together validation when a fk is involved and
# models for testing unique_together validation when a fk is involved and
# using inlineformset_factory.
# using inlineformset_factory.
@python_2_unicode_compatible
@python_2_unicode_compatible
...
@@ -156,6 +174,7 @@ class Repository(models.Model):
...
@@ -156,6 +174,7 @@ class Repository(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Revision
(
models
.
Model
):
class
Revision
(
models
.
Model
):
repository
=
models
.
ForeignKey
(
Repository
)
repository
=
models
.
ForeignKey
(
Repository
)
...
@@ -167,21 +186,25 @@ class Revision(models.Model):
...
@@ -167,21 +186,25 @@ class Revision(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s (
%
s)"
%
(
self
.
revision
,
six
.
text_type
(
self
.
repository
))
return
"
%
s (
%
s)"
%
(
self
.
revision
,
six
.
text_type
(
self
.
repository
))
# models for testing callable defaults (see bug #7975). If you define a model
# models for testing callable defaults (see bug #7975). If you define a model
# with a callable default value, you cannot rely on the initial value in a
# with a callable default value, you cannot rely on the initial value in a
# form.
# form.
class
Person
(
models
.
Model
):
class
Person
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
128
)
name
=
models
.
CharField
(
max_length
=
128
)
class
Membership
(
models
.
Model
):
class
Membership
(
models
.
Model
):
person
=
models
.
ForeignKey
(
Person
)
person
=
models
.
ForeignKey
(
Person
)
date_joined
=
models
.
DateTimeField
(
default
=
datetime
.
datetime
.
now
)
date_joined
=
models
.
DateTimeField
(
default
=
datetime
.
datetime
.
now
)
karma
=
models
.
IntegerField
()
karma
=
models
.
IntegerField
()
# models for testing a null=True fk to a parent
# models for testing a null=True fk to a parent
class
Team
(
models
.
Model
):
class
Team
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
name
=
models
.
CharField
(
max_length
=
100
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Player
(
models
.
Model
):
class
Player
(
models
.
Model
):
team
=
models
.
ForeignKey
(
Team
,
null
=
True
)
team
=
models
.
ForeignKey
(
Team
,
null
=
True
)
...
@@ -190,6 +213,7 @@ class Player(models.Model):
...
@@ -190,6 +213,7 @@ class Player(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
# Models for testing custom ModelForm save methods in formsets and inline formsets
# Models for testing custom ModelForm save methods in formsets and inline formsets
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Poet
(
models
.
Model
):
class
Poet
(
models
.
Model
):
...
@@ -198,6 +222,7 @@ class Poet(models.Model):
...
@@ -198,6 +222,7 @@ class Poet(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Poem
(
models
.
Model
):
class
Poem
(
models
.
Model
):
poet
=
models
.
ForeignKey
(
Poet
)
poet
=
models
.
ForeignKey
(
Poet
)
...
@@ -206,6 +231,7 @@ class Poem(models.Model):
...
@@ -206,6 +231,7 @@ class Poem(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Post
(
models
.
Model
):
class
Post
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
50
,
unique_for_date
=
'posted'
,
blank
=
True
)
title
=
models
.
CharField
(
max_length
=
50
,
unique_for_date
=
'posted'
,
blank
=
True
)
...
...
tests/model_formsets_regress/models.py
Dosyayı görüntüle @
3f115776
...
@@ -6,23 +6,29 @@ class User(models.Model):
...
@@ -6,23 +6,29 @@ class User(models.Model):
username
=
models
.
CharField
(
max_length
=
12
,
unique
=
True
)
username
=
models
.
CharField
(
max_length
=
12
,
unique
=
True
)
serial
=
models
.
IntegerField
()
serial
=
models
.
IntegerField
()
class
UserSite
(
models
.
Model
):
class
UserSite
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
to_field
=
"username"
)
user
=
models
.
ForeignKey
(
User
,
to_field
=
"username"
)
data
=
models
.
IntegerField
()
data
=
models
.
IntegerField
()
class
Place
(
models
.
Model
):
class
Place
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
class
Restaurant
(
Place
):
class
Restaurant
(
Place
):
pass
pass
class
Manager
(
models
.
Model
):
class
Manager
(
models
.
Model
):
retaurant
=
models
.
ForeignKey
(
Restaurant
)
retaurant
=
models
.
ForeignKey
(
Restaurant
)
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
class
Network
(
models
.
Model
):
class
Network
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
15
)
name
=
models
.
CharField
(
max_length
=
15
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Host
(
models
.
Model
):
class
Host
(
models
.
Model
):
network
=
models
.
ForeignKey
(
Network
)
network
=
models
.
ForeignKey
(
Network
)
...
...
tests/model_formsets_regress/tests.py
Dosyayı görüntüle @
3f115776
...
@@ -330,6 +330,7 @@ class FormfieldCallbackTests(TestCase):
...
@@ -330,6 +330,7 @@ class FormfieldCallbackTests(TestCase):
formfield_callback
=
callback
)
formfield_callback
=
callback
)
self
.
assertCallbackCalled
(
callback
)
self
.
assertCallbackCalled
(
callback
)
class
BaseCustomDeleteFormSet
(
BaseFormSet
):
class
BaseCustomDeleteFormSet
(
BaseFormSet
):
"""
"""
A formset mix-in that lets a form decide if it's to be deleted.
A formset mix-in that lets a form decide if it's to be deleted.
...
...
tests/model_inheritance/models.py
Dosyayı görüntüle @
3f115776
...
@@ -20,6 +20,7 @@ from django.utils.encoding import python_2_unicode_compatible
...
@@ -20,6 +20,7 @@ from django.utils.encoding import python_2_unicode_compatible
# Abstract base classes
# Abstract base classes
#
#
@python_2_unicode_compatible
@python_2_unicode_compatible
class
CommonInfo
(
models
.
Model
):
class
CommonInfo
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
...
@@ -32,18 +33,22 @@ class CommonInfo(models.Model):
...
@@ -32,18 +33,22 @@ class CommonInfo(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
'
%
s
%
s'
%
(
self
.
__class__
.
__name__
,
self
.
name
)
return
'
%
s
%
s'
%
(
self
.
__class__
.
__name__
,
self
.
name
)
class
Worker
(
CommonInfo
):
class
Worker
(
CommonInfo
):
job
=
models
.
CharField
(
max_length
=
50
)
job
=
models
.
CharField
(
max_length
=
50
)
class
Student
(
CommonInfo
):
class
Student
(
CommonInfo
):
school_class
=
models
.
CharField
(
max_length
=
10
)
school_class
=
models
.
CharField
(
max_length
=
10
)
class
Meta
:
class
Meta
:
pass
pass
class
StudentWorker
(
Student
,
Worker
):
class
StudentWorker
(
Student
,
Worker
):
pass
pass
#
#
# Abstract base classes with related models
# Abstract base classes with related models
#
#
...
@@ -51,6 +56,7 @@ class StudentWorker(Student, Worker):
...
@@ -51,6 +56,7 @@ class StudentWorker(Student, Worker):
class
Post
(
models
.
Model
):
class
Post
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
50
)
title
=
models
.
CharField
(
max_length
=
50
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Attachment
(
models
.
Model
):
class
Attachment
(
models
.
Model
):
post
=
models
.
ForeignKey
(
Post
,
related_name
=
'attached_
%(class)
s_set'
)
post
=
models
.
ForeignKey
(
Post
,
related_name
=
'attached_
%(class)
s_set'
)
...
@@ -62,12 +68,15 @@ class Attachment(models.Model):
...
@@ -62,12 +68,15 @@ class Attachment(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
content
return
self
.
content
class
Comment
(
Attachment
):
class
Comment
(
Attachment
):
is_spam
=
models
.
BooleanField
(
default
=
False
)
is_spam
=
models
.
BooleanField
(
default
=
False
)
class
Link
(
Attachment
):
class
Link
(
Attachment
):
url
=
models
.
URLField
()
url
=
models
.
URLField
()
#
#
# Multi-table inheritance
# Multi-table inheritance
#
#
...
@@ -79,6 +88,7 @@ class Chef(models.Model):
...
@@ -79,6 +88,7 @@ class Chef(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the chef"
%
self
.
name
return
"
%
s the chef"
%
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Place
(
models
.
Model
):
class
Place
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
...
@@ -87,6 +97,7 @@ class Place(models.Model):
...
@@ -87,6 +97,7 @@ class Place(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the place"
%
self
.
name
return
"
%
s the place"
%
self
.
name
class
Rating
(
models
.
Model
):
class
Rating
(
models
.
Model
):
rating
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
)
rating
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
)
...
@@ -94,6 +105,7 @@ class Rating(models.Model):
...
@@ -94,6 +105,7 @@ class Rating(models.Model):
abstract
=
True
abstract
=
True
ordering
=
[
'-rating'
]
ordering
=
[
'-rating'
]
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Restaurant
(
Place
,
Rating
):
class
Restaurant
(
Place
,
Rating
):
serves_hot_dogs
=
models
.
BooleanField
(
default
=
False
)
serves_hot_dogs
=
models
.
BooleanField
(
default
=
False
)
...
@@ -106,6 +118,7 @@ class Restaurant(Place, Rating):
...
@@ -106,6 +118,7 @@ class Restaurant(Place, Rating):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the restaurant"
%
self
.
name
return
"
%
s the restaurant"
%
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
ItalianRestaurant
(
Restaurant
):
class
ItalianRestaurant
(
Restaurant
):
serves_gnocchi
=
models
.
BooleanField
(
default
=
False
)
serves_gnocchi
=
models
.
BooleanField
(
default
=
False
)
...
@@ -113,6 +126,7 @@ class ItalianRestaurant(Restaurant):
...
@@ -113,6 +126,7 @@ class ItalianRestaurant(Restaurant):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the italian restaurant"
%
self
.
name
return
"
%
s the italian restaurant"
%
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Supplier
(
Place
):
class
Supplier
(
Place
):
customers
=
models
.
ManyToManyField
(
Restaurant
,
related_name
=
'provider'
)
customers
=
models
.
ManyToManyField
(
Restaurant
,
related_name
=
'provider'
)
...
@@ -120,6 +134,7 @@ class Supplier(Place):
...
@@ -120,6 +134,7 @@ class Supplier(Place):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the supplier"
%
self
.
name
return
"
%
s the supplier"
%
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
ParkingLot
(
Place
):
class
ParkingLot
(
Place
):
# An explicit link to the parent (we can control the attribute name).
# An explicit link to the parent (we can control the attribute name).
...
@@ -129,6 +144,7 @@ class ParkingLot(Place):
...
@@ -129,6 +144,7 @@ class ParkingLot(Place):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the parking lot"
%
self
.
name
return
"
%
s the parking lot"
%
self
.
name
#
#
# Abstract base classes with related models where the sub-class has the
# Abstract base classes with related models where the sub-class has the
# same name in a different app and inherits from the same abstract base
# same name in a different app and inherits from the same abstract base
...
@@ -141,6 +157,7 @@ class ParkingLot(Place):
...
@@ -141,6 +157,7 @@ class ParkingLot(Place):
class
Title
(
models
.
Model
):
class
Title
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
50
)
title
=
models
.
CharField
(
max_length
=
50
)
class
NamedURL
(
models
.
Model
):
class
NamedURL
(
models
.
Model
):
title
=
models
.
ForeignKey
(
Title
,
related_name
=
'attached_
%(app_label)
s_
%(class)
s_set'
)
title
=
models
.
ForeignKey
(
Title
,
related_name
=
'attached_
%(app_label)
s_
%(class)
s_set'
)
url
=
models
.
URLField
()
url
=
models
.
URLField
()
...
@@ -148,6 +165,7 @@ class NamedURL(models.Model):
...
@@ -148,6 +165,7 @@ class NamedURL(models.Model):
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Copy
(
NamedURL
):
class
Copy
(
NamedURL
):
content
=
models
.
TextField
()
content
=
models
.
TextField
()
...
@@ -155,16 +173,20 @@ class Copy(NamedURL):
...
@@ -155,16 +173,20 @@ class Copy(NamedURL):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
content
return
self
.
content
class
Mixin
(
object
):
class
Mixin
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
other_attr
=
1
self
.
other_attr
=
1
super
(
Mixin
,
self
)
.
__init__
()
super
(
Mixin
,
self
)
.
__init__
()
class
MixinModel
(
models
.
Model
,
Mixin
):
class
MixinModel
(
models
.
Model
,
Mixin
):
pass
pass
class
Base
(
models
.
Model
):
class
Base
(
models
.
Model
):
titles
=
models
.
ManyToManyField
(
Title
)
titles
=
models
.
ManyToManyField
(
Title
)
class
SubBase
(
Base
):
class
SubBase
(
Base
):
sub_id
=
models
.
IntegerField
(
primary_key
=
True
)
sub_id
=
models
.
IntegerField
(
primary_key
=
True
)
tests/model_inheritance_regress/models.py
Dosyayı görüntüle @
3f115776
...
@@ -5,6 +5,7 @@ import datetime
...
@@ -5,6 +5,7 @@ import datetime
from
django.db
import
models
from
django.db
import
models
from
django.utils.encoding
import
python_2_unicode_compatible
from
django.utils.encoding
import
python_2_unicode_compatible
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Place
(
models
.
Model
):
class
Place
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
...
@@ -16,6 +17,7 @@ class Place(models.Model):
...
@@ -16,6 +17,7 @@ class Place(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the place"
%
self
.
name
return
"
%
s the place"
%
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Restaurant
(
Place
):
class
Restaurant
(
Place
):
serves_hot_dogs
=
models
.
BooleanField
(
default
=
False
)
serves_hot_dogs
=
models
.
BooleanField
(
default
=
False
)
...
@@ -24,6 +26,7 @@ class Restaurant(Place):
...
@@ -24,6 +26,7 @@ class Restaurant(Place):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the restaurant"
%
self
.
name
return
"
%
s the restaurant"
%
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
ItalianRestaurant
(
Restaurant
):
class
ItalianRestaurant
(
Restaurant
):
serves_gnocchi
=
models
.
BooleanField
(
default
=
False
)
serves_gnocchi
=
models
.
BooleanField
(
default
=
False
)
...
@@ -31,6 +34,7 @@ class ItalianRestaurant(Restaurant):
...
@@ -31,6 +34,7 @@ class ItalianRestaurant(Restaurant):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the italian restaurant"
%
self
.
name
return
"
%
s the italian restaurant"
%
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
ParkingLot
(
Place
):
class
ParkingLot
(
Place
):
# An explicit link to the parent (we can control the attribute name).
# An explicit link to the parent (we can control the attribute name).
...
@@ -40,16 +44,19 @@ class ParkingLot(Place):
...
@@ -40,16 +44,19 @@ class ParkingLot(Place):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the parking lot"
%
self
.
name
return
"
%
s the parking lot"
%
self
.
name
class
ParkingLot2
(
Place
):
class
ParkingLot2
(
Place
):
# In lieu of any other connector, an existing OneToOneField will be
# In lieu of any other connector, an existing OneToOneField will be
# promoted to the primary key.
# promoted to the primary key.
parent
=
models
.
OneToOneField
(
Place
)
parent
=
models
.
OneToOneField
(
Place
)
class
ParkingLot3
(
Place
):
class
ParkingLot3
(
Place
):
# The parent_link connector need not be the pk on the model.
# The parent_link connector need not be the pk on the model.
primary_key
=
models
.
AutoField
(
primary_key
=
True
)
primary_key
=
models
.
AutoField
(
primary_key
=
True
)
parent
=
models
.
OneToOneField
(
Place
,
parent_link
=
True
)
parent
=
models
.
OneToOneField
(
Place
,
parent_link
=
True
)
class
ParkingLot4
(
models
.
Model
):
class
ParkingLot4
(
models
.
Model
):
# Test parent_link connector can be discovered in abstract classes.
# Test parent_link connector can be discovered in abstract classes.
parent
=
models
.
OneToOneField
(
Place
,
parent_link
=
True
)
parent
=
models
.
OneToOneField
(
Place
,
parent_link
=
True
)
...
@@ -57,31 +64,40 @@ class ParkingLot4(models.Model):
...
@@ -57,31 +64,40 @@ class ParkingLot4(models.Model):
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
class
ParkingLot4A
(
ParkingLot4
,
Place
):
class
ParkingLot4A
(
ParkingLot4
,
Place
):
pass
pass
class
ParkingLot4B
(
Place
,
ParkingLot4
):
class
ParkingLot4B
(
Place
,
ParkingLot4
):
pass
pass
class
Supplier
(
models
.
Model
):
class
Supplier
(
models
.
Model
):
restaurant
=
models
.
ForeignKey
(
Restaurant
)
restaurant
=
models
.
ForeignKey
(
Restaurant
)
class
Wholesaler
(
Supplier
):
class
Wholesaler
(
Supplier
):
retailer
=
models
.
ForeignKey
(
Supplier
,
related_name
=
'wholesale_supplier'
)
retailer
=
models
.
ForeignKey
(
Supplier
,
related_name
=
'wholesale_supplier'
)
class
Parent
(
models
.
Model
):
class
Parent
(
models
.
Model
):
created
=
models
.
DateTimeField
(
default
=
datetime
.
datetime
.
now
)
created
=
models
.
DateTimeField
(
default
=
datetime
.
datetime
.
now
)
class
Child
(
Parent
):
class
Child
(
Parent
):
name
=
models
.
CharField
(
max_length
=
10
)
name
=
models
.
CharField
(
max_length
=
10
)
class
SelfRefParent
(
models
.
Model
):
class
SelfRefParent
(
models
.
Model
):
parent_data
=
models
.
IntegerField
()
parent_data
=
models
.
IntegerField
()
self_data
=
models
.
ForeignKey
(
'self'
,
null
=
True
)
self_data
=
models
.
ForeignKey
(
'self'
,
null
=
True
)
class
SelfRefChild
(
SelfRefParent
):
class
SelfRefChild
(
SelfRefParent
):
child_data
=
models
.
IntegerField
()
child_data
=
models
.
IntegerField
()
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Article
(
models
.
Model
):
class
Article
(
models
.
Model
):
headline
=
models
.
CharField
(
max_length
=
100
)
headline
=
models
.
CharField
(
max_length
=
100
)
...
@@ -93,24 +109,30 @@ class Article(models.Model):
...
@@ -93,24 +109,30 @@ class Article(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
headline
return
self
.
headline
class
ArticleWithAuthor
(
Article
):
class
ArticleWithAuthor
(
Article
):
author
=
models
.
CharField
(
max_length
=
100
)
author
=
models
.
CharField
(
max_length
=
100
)
class
M2MBase
(
models
.
Model
):
class
M2MBase
(
models
.
Model
):
articles
=
models
.
ManyToManyField
(
Article
)
articles
=
models
.
ManyToManyField
(
Article
)
class
M2MChild
(
M2MBase
):
class
M2MChild
(
M2MBase
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
class
Evaluation
(
Article
):
class
Evaluation
(
Article
):
quality
=
models
.
IntegerField
()
quality
=
models
.
IntegerField
()
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
class
QualityControl
(
Evaluation
):
class
QualityControl
(
Evaluation
):
assignee
=
models
.
CharField
(
max_length
=
50
)
assignee
=
models
.
CharField
(
max_length
=
50
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
BaseM
(
models
.
Model
):
class
BaseM
(
models
.
Model
):
base_name
=
models
.
CharField
(
max_length
=
100
)
base_name
=
models
.
CharField
(
max_length
=
100
)
...
@@ -118,6 +140,7 @@ class BaseM(models.Model):
...
@@ -118,6 +140,7 @@ class BaseM(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
base_name
return
self
.
base_name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
DerivedM
(
BaseM
):
class
DerivedM
(
BaseM
):
customPK
=
models
.
IntegerField
(
primary_key
=
True
)
customPK
=
models
.
IntegerField
(
primary_key
=
True
)
...
@@ -127,6 +150,7 @@ class DerivedM(BaseM):
...
@@ -127,6 +150,7 @@ class DerivedM(BaseM):
return
"PK =
%
d, base_name =
%
s, derived_name =
%
s"
%
(
return
"PK =
%
d, base_name =
%
s, derived_name =
%
s"
%
(
self
.
customPK
,
self
.
base_name
,
self
.
derived_name
)
self
.
customPK
,
self
.
base_name
,
self
.
derived_name
)
class
AuditBase
(
models
.
Model
):
class
AuditBase
(
models
.
Model
):
planned_date
=
models
.
DateField
()
planned_date
=
models
.
DateField
()
...
@@ -134,13 +158,16 @@ class AuditBase(models.Model):
...
@@ -134,13 +158,16 @@ class AuditBase(models.Model):
abstract
=
True
abstract
=
True
verbose_name_plural
=
'Audits'
verbose_name_plural
=
'Audits'
class
CertificationAudit
(
AuditBase
):
class
CertificationAudit
(
AuditBase
):
class
Meta
(
AuditBase
.
Meta
):
class
Meta
(
AuditBase
.
Meta
):
abstract
=
True
abstract
=
True
class
InternalCertificationAudit
(
CertificationAudit
):
class
InternalCertificationAudit
(
CertificationAudit
):
auditing_dept
=
models
.
CharField
(
max_length
=
20
)
auditing_dept
=
models
.
CharField
(
max_length
=
20
)
# Check that abstract classes don't get m2m tables autocreated.
# Check that abstract classes don't get m2m tables autocreated.
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Person
(
models
.
Model
):
class
Person
(
models
.
Model
):
...
@@ -152,6 +179,7 @@ class Person(models.Model):
...
@@ -152,6 +179,7 @@ class Person(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
AbstractEvent
(
models
.
Model
):
class
AbstractEvent
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
name
=
models
.
CharField
(
max_length
=
100
)
...
@@ -164,35 +192,44 @@ class AbstractEvent(models.Model):
...
@@ -164,35 +192,44 @@ class AbstractEvent(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
class
BirthdayParty
(
AbstractEvent
):
class
BirthdayParty
(
AbstractEvent
):
pass
pass
class
BachelorParty
(
AbstractEvent
):
class
BachelorParty
(
AbstractEvent
):
pass
pass
class
MessyBachelorParty
(
BachelorParty
):
class
MessyBachelorParty
(
BachelorParty
):
pass
pass
# Check concrete -> abstract -> concrete inheritance
# Check concrete -> abstract -> concrete inheritance
class
SearchableLocation
(
models
.
Model
):
class
SearchableLocation
(
models
.
Model
):
keywords
=
models
.
CharField
(
max_length
=
256
)
keywords
=
models
.
CharField
(
max_length
=
256
)
class
Station
(
SearchableLocation
):
class
Station
(
SearchableLocation
):
name
=
models
.
CharField
(
max_length
=
128
)
name
=
models
.
CharField
(
max_length
=
128
)
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
class
BusStation
(
Station
):
class
BusStation
(
Station
):
bus_routes
=
models
.
CommaSeparatedIntegerField
(
max_length
=
128
)
bus_routes
=
models
.
CommaSeparatedIntegerField
(
max_length
=
128
)
inbound
=
models
.
BooleanField
(
default
=
False
)
inbound
=
models
.
BooleanField
(
default
=
False
)
class
TrainStation
(
Station
):
class
TrainStation
(
Station
):
zone
=
models
.
IntegerField
()
zone
=
models
.
IntegerField
()
class
User
(
models
.
Model
):
class
User
(
models
.
Model
):
username
=
models
.
CharField
(
max_length
=
30
,
unique
=
True
)
username
=
models
.
CharField
(
max_length
=
30
,
unique
=
True
)
class
Profile
(
User
):
class
Profile
(
User
):
profile_id
=
models
.
AutoField
(
primary_key
=
True
)
profile_id
=
models
.
AutoField
(
primary_key
=
True
)
extra
=
models
.
CharField
(
max_length
=
30
,
blank
=
True
)
extra
=
models
.
CharField
(
max_length
=
30
,
blank
=
True
)
tests/model_inheritance_select_related/models.py
Dosyayı görüntüle @
3f115776
...
@@ -18,6 +18,7 @@ class Place(models.Model):
...
@@ -18,6 +18,7 @@ class Place(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the place"
%
self
.
name
return
"
%
s the place"
%
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Restaurant
(
Place
):
class
Restaurant
(
Place
):
serves_sushi
=
models
.
BooleanField
(
default
=
False
)
serves_sushi
=
models
.
BooleanField
(
default
=
False
)
...
@@ -26,6 +27,7 @@ class Restaurant(Place):
...
@@ -26,6 +27,7 @@ class Restaurant(Place):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the restaurant"
%
self
.
name
return
"
%
s the restaurant"
%
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Person
(
models
.
Model
):
class
Person
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
...
...
tests/model_validation/models.py
Dosyayı görüntüle @
3f115776
...
@@ -39,6 +39,7 @@ class ManyToManyRel(models.Model):
...
@@ -39,6 +39,7 @@ class ManyToManyRel(models.Model):
# Models created as unmanaged as these aren't ever queried
# Models created as unmanaged as these aren't ever queried
managed
=
False
managed
=
False
class
FKRel
(
models
.
Model
):
class
FKRel
(
models
.
Model
):
thing1
=
models
.
ForeignKey
(
ThingWithIterableChoices
,
related_name
=
'+'
)
thing1
=
models
.
ForeignKey
(
ThingWithIterableChoices
,
related_name
=
'+'
)
thing2
=
models
.
ForeignKey
(
ThingWithIterableChoices
,
related_name
=
'+'
)
thing2
=
models
.
ForeignKey
(
ThingWithIterableChoices
,
related_name
=
'+'
)
...
...
tests/modeladmin/models.py
Dosyayı görüntüle @
3f115776
...
@@ -16,6 +16,7 @@ class Band(models.Model):
...
@@ -16,6 +16,7 @@ class Band(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
class
Concert
(
models
.
Model
):
class
Concert
(
models
.
Model
):
main_band
=
models
.
ForeignKey
(
Band
,
related_name
=
'main_concerts'
)
main_band
=
models
.
ForeignKey
(
Band
,
related_name
=
'main_concerts'
)
opening_band
=
models
.
ForeignKey
(
Band
,
related_name
=
'opening_concerts'
,
opening_band
=
models
.
ForeignKey
(
Band
,
related_name
=
'opening_concerts'
,
...
@@ -27,6 +28,7 @@ class Concert(models.Model):
...
@@ -27,6 +28,7 @@ class Concert(models.Model):
(
3
,
'Bus'
)
(
3
,
'Bus'
)
),
blank
=
True
)
),
blank
=
True
)
class
ValidationTestModel
(
models
.
Model
):
class
ValidationTestModel
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
name
=
models
.
CharField
(
max_length
=
100
)
slug
=
models
.
SlugField
()
slug
=
models
.
SlugField
()
...
@@ -40,5 +42,6 @@ class ValidationTestModel(models.Model):
...
@@ -40,5 +42,6 @@ class ValidationTestModel(models.Model):
def
decade_published_in
(
self
):
def
decade_published_in
(
self
):
return
self
.
pub_date
.
strftime
(
'
%
Y'
)[:
3
]
+
"0's"
return
self
.
pub_date
.
strftime
(
'
%
Y'
)[:
3
]
+
"0's"
class
ValidationTestInlineModel
(
models
.
Model
):
class
ValidationTestInlineModel
(
models
.
Model
):
parent
=
models
.
ForeignKey
(
ValidationTestModel
)
parent
=
models
.
ForeignKey
(
ValidationTestModel
)
tests/multiple_database/models.py
Dosyayı görüntüle @
3f115776
...
@@ -18,10 +18,12 @@ class Review(models.Model):
...
@@ -18,10 +18,12 @@ class Review(models.Model):
class
Meta
:
class
Meta
:
ordering
=
(
'source'
,)
ordering
=
(
'source'
,)
class
PersonManager
(
models
.
Manager
):
class
PersonManager
(
models
.
Manager
):
def
get_by_natural_key
(
self
,
name
):
def
get_by_natural_key
(
self
,
name
):
return
self
.
get
(
name
=
name
)
return
self
.
get
(
name
=
name
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Person
(
models
.
Model
):
class
Person
(
models
.
Model
):
objects
=
PersonManager
()
objects
=
PersonManager
()
...
@@ -33,6 +35,7 @@ class Person(models.Model):
...
@@ -33,6 +35,7 @@ class Person(models.Model):
class
Meta
:
class
Meta
:
ordering
=
(
'name'
,)
ordering
=
(
'name'
,)
# This book manager doesn't do anything interesting; it just
# This book manager doesn't do anything interesting; it just
# exists to strip out the 'extra_arg' argument to certain
# exists to strip out the 'extra_arg' argument to certain
# calls. This argument is used to establish that the BookManager
# calls. This argument is used to establish that the BookManager
...
@@ -46,6 +49,7 @@ class BookManager(models.Manager):
...
@@ -46,6 +49,7 @@ class BookManager(models.Manager):
kwargs
.
pop
(
'extra_arg'
,
None
)
kwargs
.
pop
(
'extra_arg'
,
None
)
return
super
(
BookManager
,
self
)
.
get_or_create
(
*
args
,
**
kwargs
)
return
super
(
BookManager
,
self
)
.
get_or_create
(
*
args
,
**
kwargs
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Book
(
models
.
Model
):
class
Book
(
models
.
Model
):
objects
=
BookManager
()
objects
=
BookManager
()
...
@@ -62,6 +66,7 @@ class Book(models.Model):
...
@@ -62,6 +66,7 @@ class Book(models.Model):
class
Meta
:
class
Meta
:
ordering
=
(
'title'
,)
ordering
=
(
'title'
,)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Pet
(
models
.
Model
):
class
Pet
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
name
=
models
.
CharField
(
max_length
=
100
)
...
@@ -73,6 +78,7 @@ class Pet(models.Model):
...
@@ -73,6 +78,7 @@ class Pet(models.Model):
class
Meta
:
class
Meta
:
ordering
=
(
'name'
,)
ordering
=
(
'name'
,)
class
UserProfile
(
models
.
Model
):
class
UserProfile
(
models
.
Model
):
user
=
models
.
OneToOneField
(
User
,
null
=
True
)
user
=
models
.
OneToOneField
(
User
,
null
=
True
)
flavor
=
models
.
CharField
(
max_length
=
100
)
flavor
=
models
.
CharField
(
max_length
=
100
)
...
...
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