C
C
Cyber_bober2016-03-09 13:09:00
Django
Cyber_bober, 2016-03-09 13:09:00

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

3 answer(s)
S
Sergey Gornostaev, 2016-03-10
@Cyber_bober

models.py

class Post(models.Model):
    owner = models.OneToOneField(User, verbose_name='Владелец', related_name='post')

views.py
@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)
        ...

S
sim3x, 2016-03-09
@sim3x

Create custom user with content field

R
Rostislav Grigoriev, 2016-03-09
@crazyzubr

The solution you provided is fine. You can create a page using signals .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question