-1

I am new to django and working on a project where i want to make manager and admin. I have made the admin i.e. superuser but i have no idea how can i make a manager.

I have tried to make a manager but it doesn't work for me. here is my views.py from where the manager is being detected.

def login(request):
if request.method =='POST':
    # print(request.POST)
    username = request.POST['username']
    password = request.POST['password']

    user = auth.authenticate(username=username, password=password)

    if user is not None:
        auth.login(request, user)
        print (user.has_perm('app.edit_task'))
        # return redirect('index')

        if user.is_superuser:
            return redirect('master')

        # elif user.has_perm('app.edit_task'):
        #     return redirect('manager')
        elif user.is_staff:
            return redirect('manager')
        else:
            return redirect('index')

    else:
        messages.error(request, 'Invalid Credentials')
        return redirect('login')    
else: 
    return render(request, 'vadash/sign-in.html')

here is my models.py

class manager(models.Model):
name = models.CharField(max_length= 500)
designation = models.CharField(max_length= 500)
class Meta:
    permissions = [
        ("edit_task", "can edit the task"),
    ]

def __str__(self):
    return self.name


class Create_Team(models.Model):
first_name = models.CharField(max_length= 50)
last_name = models.CharField(max_length= 50)
company_name = models.CharField(max_length= 100)
address = models.CharField(max_length= 1000)
state = models.CharField(max_length= 100)
status = models.CharField(max_length= 30)
managers = models.ForeignKey('manager', on_delete = models.SET_NULL, null=True)

I want to known that how can i make a manager and when ever a manager will be made then it will be reflected in the database of Create_Team also..

Sahil Sharma
  • 65
  • 1
  • 1
  • 12

2 Answers2

0

If you want to use the django auth system for creating different user types, you can create superuser with curstom user model. See this.

Pedram Parsian
  • 3,750
  • 3
  • 19
  • 34
  • Your manager class should inherit from **AbstractBaseUser**, not models.Model. follow instructions on [this](https://www.codingforentrepreneurs.com/blog/how-to-create-a-custom-django-user-model/) link. – Pedram Parsian May 08 '19 at 07:54
  • can you please write some code for me so i can understand better – Sahil Sharma May 08 '19 at 09:04
  • the link provided in the comment has a full example of what you want. Just change the code to fit your needs. You can also refer to the [django documentation](https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#a-full-example) for more information. – Pedram Parsian May 08 '19 at 12:44
0

check this if it helps ,Here and also this website is great for learning django from scratch

ps: You may need to scroll for your answer

Community
  • 1
  • 1
Urvin
  • 71
  • 9