How to use Django-Phonenumber-Field Packed? (TR) | Django-Phonenumber-Field Nasıl Kullanılır?

in #utopian-io8 years ago (edited)

For the english readers; We have a project written with Django. In this project we want to use the phone number. We can do this with Django-Phonenumber-Field. Why should we use it? Where to find a solution. Includes example usage.

Note: I threw the codes as picture. Because it's deformity. It looks bad.

What Will I Learn?

Django ile yazilan bir projemiz var. Bu projede telefon numarası kullanmak istiyoruz. Django-Phonenumber-Field ile bunu yapabiliyoruz. Doğrulanmış telefon numarası girmenizi sağlıyor. Hatali bir formatta telefon numarası girmesini önlüyor.

Supported versions

  • Python2 ve Python3(tercih edilen)
  • Django 1.11 üstü (tercih edilen)

Difficulty

  • Basic

Neden kullanayım?

Django projelerinde telefon numarası kullanmak istiyorsak bu paketi kullanabilir. Paket veritabani, formlar ve serializer tarafında destek sunuyor. Hem ön tarafta hem arkada tarafta validate imkanı bulunuyor. Regex ile uğraşmadan evrensel bir telefon doğrulama sistemi kullanmamıza yarıyor. Basit ve temel işleri paketler ile kullanmak, projenin versiyon olmasında kolaylık sunuyor.

Django-Phonenumber-Field nasıl kurulur?

Bunun için Python paket kurucusuna ihtiyaciniz var. Genellikle zaten bilgisayarinizda kurulu olarak bulunuyor. Ancak kurulu değilde how to install pip ile google'dan kendi işletim sisteminize göre uygun olanı indirebilirsiniz. Aşağıdaki komut ile kurulumu yapabilirsiniz.

pip install django-phonenumber-field

Kurulumu tamaladıktan sonra django projenizin settings.py kısmına eklemeniz gerekiyor! Bu çok önemli bir ayrıntı...

INSTALLED_APPS = [
    ...
    'phonenumber_field',
    ...
]

Daha sfesifik bir gösterim:

Screen Shot 2018-01-30 at 11.58.17.png

Uyarı! Dikkat edin; paketin ismi ile ayarlara eklediğiniz isim aynı değil. Tam olarak eklemeniz gereken isim budur. : 'phonenumber_field'

Projede Kullanım Şekli

Modelde kullanmak

Bu model telefon rehberi uygulaması için oluşturulmuştur.

Screen Shot 2018-01-30 at 12.34.41.png

Form ve Serializer kullanmak

Istemci tarafından gelen istekleri analiz etmek için Form veya Serializer kullanılır.

Screen Shot 2018-01-30 at 12.34.46.png

Örnek View Kullanımı

Son olarak istemciye şablonu şu şekilde sunabiliyoruz. Sunduğumuz şablonu form = PhoneForm(request.POST) anlamlı hale getiriyoruz.
Screen Shot 2018-01-30 at 12.34.51.png

Sorunuz mu var?

Bir sorun ile karşılaşırsanız bana çekinmeden sorabilirsiniz. Teşekkür ederim.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Ben bu işlem için direk model de integer field tanımlamıştım :D bu şekilde kullanmak daha mı iyi ? yaptıgım seyın zararı olmadı ama emin olamadım şimdi :D sence fark ediyormu integer field veya bu

Projenin ölçeği ile alakalı bu durum. Ben genelde bu tarz paketleri seviyorum. Disipline sokuyor insanı. Bir API gelistirirsen mesela bu tarz validate fieldlar iyi oluyor :)

This post has received a 2.24 % upvote from @drotto thanks to: @tolgahanuzun.

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @tolgahanuzun I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.09
TRX 0.32
JST 0.032
BTC 107968.52
ETH 3888.76
USDT 1.00
SBD 0.57