Answer the question
In order to leave comments, you need to log in
How to allow user to create only one post?
Hello, I want the user to be able to create only one post/page and work with the application within this page. How to implement logic? When registering, create a page with the user ID and display it for editing?
Answer the question
In order to leave comments, you need to log in
models.py
class Post(models.Model):
owner = models.OneToOneField(User, verbose_name='Владелец', related_name='post')
@login_required
dev personal_page(request):
if request.method == 'GET':
post = request.user.post
form = WorkForm() if post else PostCreateForm()
return render(request, 'personal_page.hmtl', {'form': form })
elif request.method == 'POST':
post = Post.objects.get_or_create(owner=request.user)
...
The solution you provided is fine. You can create a page using signals .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question