Hi,
On Wednesday, January 28, 2015 at 12:04:06 AM UTC-5, Karim Gorjux wrote:
-- Not sure about whether it's a good idea or not. If statements might also be good enough.
Be careful with security, but in theory something like this should work:
method_name = 'person' + person.type
method = getattr(self, method_name)
output = method()
Collin
On Wednesday, January 28, 2015 at 12:04:06 AM UTC-5, Karim Gorjux wrote:
Hi! I would like to render views based on the user. I have some differents type of users on my app and I would like to create a class like this one for the view:class MyView(MyCustomView) # MyCustomView subclass Viewdef __init__(self, *args, **kwargs):# common code for all personsdef personA(self):# code for personAdef personB(self):# code for personA# ....def personN(self):# code for personAdef anyPerson(self)# For any user non listed aboveThen if the MyView is run, the function based on the user is automatically fired.My doubts (at the moment):1) Do you think is the a good way to face the problem?2) I have methods in the models to know what person is logged. How I can automatically load the right function in the class based on the user?Thank you--Karim N. Gorjux
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7c787485-1566-4aaf-af91-be853337e107%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment