Person Model
class Person( models.Model ):
first_name = models.CharField( max_length=50 )
last_name = models.CharField( max_length=50 )
def __str__(self):
return "{0} {1}".format( self.first_name, self.last_name )
View Function
def getPersonData(request):
currPersonData = {}
# get current user
currentUser = request.user
# create a person object based on who is logged in.
person = Person.objects.create(first_name=currentUser.first_name,
last_name=currentUser.last_name)
# getting front loaded personMeta, that user CANNOT provide
# get front-loaded person data based on who is currently logged in
personDetails = PersonMeta.objects.filter(legal_first_name=currentUser.first_name,
legal_last_name=currentUser.last_name).values()
# setting hash key for dict
currUserKey = "{0} {1}".format(currentUser.first_name, currentUser.last_name)
# setting dictionary
# data[currUserKey] = currentUser
# if person details is not false
if (personDetails):
currPersonData[currUserKey] = personDetails
return currPersonData
View Call
def signup(request):
currPersonData = getPersonData( request )
return render( request, '/signup.html/', {'data': sorted( currPersonData.items( ) )}, )
URL
url(r'^signup/$', views.signup),
Template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SignUp</title>
</head>
<body>
{% for tuple in data %}
<p>Tuple key: {{ tuple.0 }}</p>
{% for key, value in tuple.1.0.items %}
<p>Dict key, value: {{ key }}: {{ value }}</p>
{% endfor %}
{% endfor %}
{% for values in eb %}
<p>values</p>
{% endfor %}
</body>
</html>
All of the above seems to be working the way I expect it to. I can get
the data I am after and pass it to a template. Now I would like take all
objects, of the below model, and pass all these objects it to my
'/signup.html/' so I can start from processing.
class Elective( models.Model ):
elective_title = models.CharField( max_length=100 )
elective_description = models.CharField( max_length=100 )
def __str__(self):
return "{0}".format( self.elective_title )
I tried following Django Pass Multiple Models to one Template
and Refer to multiple Models in View/Template in Django
With unsuccessful results, and now that I have been working on this for some time now I thought my next best move is to ask for help.
All of the above seems to be working the way I expect it to. I can get
the data I am after and pass it to a template. Now I would like take all
objects, of the below model, and pass all these objects it to my
'/signup.html/' IN ADDTION to what is being passed above so I can start form processing.
class Elective( models.Model ):
elective_title = models.CharField( max_length=100 )
elective_description = models.CharField( max_length=100 )
def __str__(self):
return "{0}".format( self.elective_title )