Django(1.7) admin - separate user-profile section

26 views
Skip to first unread message

Flemming Hansen

unread,
Mar 4, 2015, 7:15:32 PM3/4/15
to django...@googlegroups.com
Hi all,

I need to make a `passwordless` token system, and want to have a "Home › Passwordless › User tokens" in the Admin section. For the "User tokens" `list_display` I need all the "Users". (I do _not_ want to display the token information on the regular "User"-admin as just an extended "profile".) 

Any ideas on how to go about doing this?

So far I have this skeleton in `passwordless/model.py`, but I probably need some magic in `passwordless/admin.py` to list all the users with links to a custom token-manager form with custom widgets (create-token button, delete token button etc)...

from django.db import models
import jwt

class UserTokens(models.Model):
   
class Meta:
        verbose_name
= "User tokens"
        verbose_name_plural
= "User tokens"

    user
= models.OneToOneField(User)


class TokenBase(models.Model):
   
class Meta:
       
abstract = True

    token
= models.CharField(max_length=1000)    
    created_ts
= models.DateTimeField('Date created')
    expires_ts
= models.DateTimeField('Date expired')

   
def __str__(self):
       
return self.user.email


class AuthenticateToken(TokenBase):
    manager
= models.OneToOneField(UserTokens)

   
def validate(self, token):
       
pass    


class AuthorizeToken(TokenBase):  
    manager
= models.ForeignKey(UserTokens)
    revoked_ts
= models.DateTimeField('Date revoked')

   
def validate(self, token):
       
pass  


Collin Anderson

unread,
Mar 7, 2015, 12:48:20 AM3/7/15
to django...@googlegroups.com
Hi,

If you just add a custom __str__ (or __unicode__ on py2) it might do what you want.

def __str__(self):
    return str(user)

Otherwise, in UserTokenAdmin, set list_display = ['user']

Collin
Reply all
Reply to author
Forward
0 new messages