开发者

Extending Django-Admin Login (username, password, sites)

I'm trying to extend Django Admin Login. Most of the resources pointed towards extending views after the Login.

I wanted to add sites to the Login criteria.

So instead of

  • Username
  • Password

It will be

  • Username
  • Password
  • Site

Such th开发者_Python百科at the Site will check whether the user belongs to the Site as admin and if it is, it will load only data belongs to the site.

Thanks

Cheers, Mickey


I am not sure because I am newbee in django.

I would copy the admin code from the original django code in my profject folder. Then I would change it like you want it and put it in installed apps.

I hope, I could help you. As I said, I am a newbee in django.

Craphunter


You use user profiles for this.

Here's a basic example (this code would go in your app's models.py):

from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save

# Define a signal handler to be called after saving
# a User object
def user_save_handler(sender, **kwargs):
    # If the save was creating a new user as opposed
    # to updating an existing one, then create a 
    # UserProfile object and associate it with the User
    if kwargs['created']:
        # kwargs['instance'] is the User object we just
        # created
        UserProfile(user=kwargs['instance']).save()

# Hook the signal handler up to the User model's post_save
# signal
post_save.connect(user_save_handler, sender=User)

# Define your UserProfile class as usual. 
class UserProfile(models.Model):
    # user is a one-to-one reference to the associated
    # User object. You need this field
    user = models.OneToOneField(User)

    # Now define any other fields you care about
    birthday = models.DateField()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜