[英]Django different types of user
我想用Django建立一個簡單的網站,到目前為止,我已經制作了一份注冊表格,每個人都可以注冊並發布一些公告。
對於下一個階段,我想讓用戶默認情況下只能查看公告,我還希望其他類型的用戶可以查看和創建公告。
我應該如何建立我的用戶模型和注冊表格? 我應該使用權限或AbstractUser之類的東西嗎?
我正在使用的當前注冊forms.py就像
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import get_user_model
class UserCreateForm(UserCreationForm):
class Meta:
fields = ("username", "email", "password1", "password2")
model = get_user_model()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["username"].label = "Display name"
self.fields["email"].label = "Email address"
對公告的看法就像
#show all announcement
class AnnouncementListView(ListView):
...
#show a specific announcement
class PostDetailView(DetailView):
...
#create a announcement
class CreatePostView(LoginRequiredMixin,CreateView):
...
謝謝!
從django管理員創建組( https://docs.djangoproject.com/en/1.11/topics/auth/ )。 然后為您的CreatePostView編寫裝飾器。 https://djangosnippets.org/snippets/1703/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.