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
b9fceadf
Kaydet (Commit)
b9fceadf
authored
Tem 05, 2013
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #19539 -- Updated custom model fields example for Python 3.
Thanks astorije@ for the report.
üst
3e60cc29
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
custom-model-fields.txt
docs/howto/custom-model-fields.txt
+16
-2
No files found.
docs/howto/custom-model-fields.txt
Dosyayı görüntüle @
b9fceadf
...
...
@@ -249,7 +249,7 @@ appropriate Python object. The details of how this happens internally are a
little complex, but the code you need to write in your ``Field`` class is
simple: make sure your field subclass uses a special metaclass:
For example::
For example
, on Python 2
::
class HandField(models.Field):
...
...
@@ -258,7 +258,21 @@ For example::
__metaclass__ = models.SubfieldBase
def __init__(self, *args, **kwargs):
# ...
...
On Python 3, in lieu of setting the ``__metaclass__`` attribute, add
``metaclass`` to the class definition::
class HandField(models.Field, metaclass=models.SubfieldBase):
...
If you want your code to work on Python 2 & 3, you can use
:func:`six.with_metaclass`::
from django.utils.six import with_metaclass
class HandField(with_metaclass(models.SubfieldBase, models.Field)):
...
This ensures that the :meth:`.to_python` method, documented below, will always
be called when the attribute is initialized.
...
...
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