ရွှေ့ပြောင်းခြင်းတွင် စူပါအသုံးပြုသူမရှိပါက Django သည် တစ်ခုကို ဖန်တီးမည်ဖြစ်သည်။
I have a migration that creates a superuser if it does not exist. <code>def create_superuser(apps, schema_editor): User = apps.get_model('auth', 'User') if not User.objects.filter(username='admin').exists(): User.objects.create_superuser('admin', 'admin@example.com', 'password') class Migration(migrations.Migration): dependencies = [ ('myapp', '0001_initial'), ] operations = [ migrations.RunPython(create_superuser), ] </code>
ပထမစာကြောင်းက တစ်ခုမှ မရှိသေးဘူးဆိုရင် superuser တစ်ခုကို ဖန်တီးပေးမယ့် function တစ်ခု ဖန်တီးပေးတယ်။
ဒုတိယစာကြောင်းသည် 'auth' အက်ပ်မှ အသုံးပြုသူမော်ဒယ်ကို ရရှိသည်။
တတိယစာကြောင်းသည် သုံးစွဲသူအမည် 'admin' ရှိမရှိ စစ်ဆေးသည်။ မဟုတ်ရင်၊
စတုတ္ထစာကြောင်းသည် သုံးစွဲသူအမည် 'admin'၊ အီးမေးလ်လိပ်စာ 'admin@example.com' နှင့် စကားဝှက် 'စကားဝှက်' တို့ဖြင့် စူပါအသုံးပြုသူကို ဖန်တီးပေးသည်။
ပဉ္စမနှင့် ဆဋ္ဌမလိုင်းများသည် ရွှေ့ပြောင်းခြင်းအတန်းကို ဖန်တီးပြီး ၎င်းသည် အက်ပ် 'myapp' ရှိ ရွှေ့ပြောင်းခြင်း '0001_initial' ပေါ်တွင် မူတည်ကြောင်း သတ်မှတ်ပါ။
ပြောင်းရွှေ့ခြင်းသည် 'create_superuser' လုပ်ဆောင်ချက်ကို လုပ်ဆောင်သင့်သည်ဟု သတ္တမစာကြောင်းက သတ်မှတ်သည်။
Superuser ဆိုတာဘာလဲ
စူပါအသုံးပြုသူသည် Django ဆိုက်တွင် စီမံခန့်ခွဲရေးဆိုင်ရာ အခွင့်ထူးများရှိသည့် အသုံးပြုသူဖြစ်သည်။ ၎င်းတို့သည် မော်ဒယ်များ၊ အမြင်များနှင့် အပလီကေးရှင်းများ ဖန်တီးခြင်းနှင့် စီမံခန့်ခွဲခြင်းကဲ့သို့သော အရာများကို လုပ်ဆောင်နိုင်သည်။