two question, common template and mutiple user type

60 views
Skip to first unread message

Man Single

unread,
May 18, 2017, 6:58:59 AM5/18/17
to Django developers (Contributions to Django itself)
Two question: 
First: There are multiple type user, for example: NormalUser, StaffUser, EnterpriseUser, the model like this:
class User(AbstractBaseUser):
    # some auth related field here


class NormalUser(User):
    # extend , not abstract


class StaffUser(User):


class EnterpriseUser(User):


class AdminUser(User):

my solution:
But EnterpriseUser, can create childuser, so enterprise_user have two type. there is one way add one user_type field to User model, represent what type the user is, or according the 
user relationship determine what the user type is: normaluser, enterpriseuser, enterprise_child_user, admin.

Second: There are two user background manager page, one for staff to manage order, enterprise. one for normaluser to manage themself order. So there are two url path: /staff_bg/  /user_bg/
But they are use the same base template, the only different is the header tab is not same. For example:

user_header.html
{% extends "core/base.html" %}
<header>
    <ul>
        <li>your orders</li>
    </ul>
</header>

staff_header.html
{% extends "core/base.html" %}
<header>
    <ul>
        <li>enterprise</li>
    </ul>
</header>

then:
user_realted.html:
{% extends "core/user_header.html" %}  # focus here
{% block body %} 
# something
{% endblock %}

then:
staff_related.html
{% extends "core/staff_header.html" %} # focus here
{% block body %} 
# something
{% endblock %}

my solution:
create core/middle.html:
{% extends the_template_name %}

then 
user_realted.html:
{% extends "core/middle.html" %}  # focus here
{% block body %} 
# something
{% endblock %}

One way write custom template processor, base one request.path pass different the_template_name( "cms/user_header.html" or "core/staff_header.html" ) to middle.html, but I think it's dirty,
and if code wrong, maybe normal user can see the staff tabs.

another way: 
pass different the_template_name to middle.html, in every view. of course, it will change every view that already wrote.

Tim Graham

unread,
May 19, 2017, 8:29:23 AM5/19/17
to Django developers (Contributions to Django itself)
Please don't post questions like this (about using Django) to this list (its topic is about developing Django). Use the django-users or the #django IRC channel list for that. 
Reply all
Reply to author
Forward
0 new messages