Question about using a model as a member in another model.

2015-12-17 Thread Pemby
Hi all,

This is totally a beginner question and if this is the incorrect forum for 
this type of question please let me know!

So I have a couple questions. 
First I have two models 

a Student (as a signup)
a Class (as a Elective) 

What is the correct way to associate nth amount of students to a class? 
Also after I associate a list / dict (or whatever we decide here), would 
adding logic as a max limit of students be added to my Elective controller 
class? Or would the logic of "Max students" in a Elective instance be 
better contained in m elective class? 
Would I use a constructor with methods in my model to check? 

here are the models for contex (still in progress) 

# Create your models here.

class SignUp(models.Model):
first = models.CharField(max_length=25, null=True, blank=False)
last = models.CharField(max_length=25, null=True, blank=False)
studentID = models.CharField(max_length=6, null=True, blank=False)
gradeChoice = models.CharField(max_length=2, choices=grd, default='1')
genChoice = models.CharField(max_length=2, choices=gender, default='1')
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
update = models.DateTimeField(auto_now_add=False, auto_now=True)

def __unicode__(self):
return smart_unicode('Student: ' + self.last + ', ' + self.first)


class Elective(models.Model):
title = models.CharField(max_length=25, null=True, blank=False)
description = models.CharField(max_length=500,null=True, blank=False)
tFname = models.CharField(max_length=25, null=True, blank=False)
tLname = models.CharField(max_length=25, null=True, blank=False)

def __unicode__(self):
return smart_unicode('Class Name:: ' + self.title)



Please let me know of you have any questions. 

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8fcda355-ec6a-4baf-8b46-88c352422e13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Model | Relationship question. Student->School Class

2015-12-21 Thread Pemby
With this code for example. 

class Students(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
classChoice1 = ?
classChoice2 = ?
classChouce3 = ?

class Class(models.Model):
class_name = models.CharField(max_length=30)
class_discription = models.CharField(max_length=30)


Say for example I have Nth students, S1 S2 S3 ... and Nth classes (as in 
college class) C1 C2 C3 ... 
And I want to create a relationship where each student can only be assigned 
to one class uniquely for each classChoice 
selected. How would I create that relationship?


-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7f6cfec3-8fc0-4353-a0a8-7d73a7b3e3e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Pass these specific model objects to one template

2016-03-21 Thread Pemby
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 





SignUp



{% for tuple in data %}
Tuple key: {{ tuple.0 }}
{% for key, value in tuple.1.0.items %}
Dict key, value: {{ key }}: {{ value }}
{% endfor %}
{% endfor %}


{% for values in eb %}
values
{% endfor %}






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. 

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/59859122-6816-4935-9bfa-530013ce994f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pass these specific model objects to one template

2016-03-21 Thread Pemby



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 )



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. 

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d9801311-3793-4931-a736-03d28ac50004%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.