Reputation: 151
I want to build a simple website with Django, and so far I have made a sign-up form that everyone can sign up and publish some announcement.
For next stage I want to make the user can only view the announcement by default, I also want to have another type of user can view and create an announcement.
How should I build my user model and sign up forms? Should I use things like permission or AbstractUser?
the current sign up forms.py I am using is like
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"
and the views about the announcement is like
#show all announcement
class AnnouncementListView(ListView):
...
#show a specific announcement
class PostDetailView(DetailView):
...
#create a announcement
class CreatePostView(LoginRequiredMixin,CreateView):
...
Thanks!
Upvotes: 0
Views: 100
Reputation: 1983
Create groups (https://docs.djangoproject.com/en/1.11/topics/auth/) from the django admin. Then write decorator for your CreatePostView.https://djangosnippets.org/snippets/1703/
Upvotes: 1