0

The challenge is to:

There is a group which named as GroupEditor User of this group( GroupEditor) can only Add , Change and Remove News- only News

But to do so user of this group(GroupEditor) when deleted news could delete your news which he added

And that's actually the question is that how to implement it ? Maybe in the admin panel have to do something?

It is admin.py

class PublishAdmin(admin.ModelAdmin):
    fields = ['author', 'category', 'img', 'title', 'content', 'keywords', 'publish', 'active']

class CategoryAdmin(admin.ModelAdmin):
    fields = ['title']

admin.site.register(Publication, PublishAdmin)
admin.site.register(Category, CategoryAdmin)

It is method in views.py with which i registered user for GroupEditor

def register(request):
    if request.user.is_authenticated(): return redirect('/')
    c={}
    c.update(csrf(request))
    c.setdefault('form', auth.forms.UserCreationForm)
    if request.POST:
        newform = auth.forms.UserCreationForm(request.POST)
        if newform.is_valid():
            nf=newform.save(commit = False)
            nf.is_staff = True
            nf.save()

            user=auth.authenticate(
                username = newform.cleaned_data['username'], 
                password = newform.cleaned_data['password1']
                )
            group = auth.models.Group.objects.get(name = 'Redactor')
            user.groups.add(group)
            auth.login(request, user)
            return redirect('/')
        else:
            c['form'] = newform
    return render(request, 'register.html',c)
karthikr
  • 97,368
  • 26
  • 197
  • 188
Milad
  • 1
  • 2
  • what do you mean by this statement `But to do so user of this group(GroupEditor) when deleted news could delete your news which he added`? – karthikr Feb 06 '16 at 13:58
  • Users of this group should only delete his publication – Milad Feb 06 '16 at 14:07

0 Answers0