query on models

19 views
Skip to first unread message

Anushree

unread,
May 7, 2014, 9:24:38 AM5/7/14
to django...@googlegroups.com
I have the following models. I want to retrieve list of question banks related to a particular subject. Is it possible to do without modifying the existing data models?Thank you
class Subject(models.Model):
name = models.CharField(max_length = 255)
desc = models.TextField(blank=True)
def __unicode__(self):
return self.name

class QuestionBank(models.Model):
name = models.CharField(max_length=255)
desc = models.TextField()
def __unicode__(self):
return self.name

class Ques(models.Model):
content = models.TextField()
ques_type = models.CharField(max_length = 1 , default= 'A')
score = models.PositiveSmallIntegerField(max_length = 1 , default= 1)
ques_bank = models.ForeignKey(QuestionBank)
subject = models.ForeignKey(Subject)

Rafael E. Ferrero

unread,
May 7, 2014, 10:05:27 AM5/7/14
to django...@googlegroups.com
Just filtering Ques model (imho)

--
Rafael E. Ferrero


--
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...@googlegroups.com.
To post to this group, send email to django...@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/66442114-cda1-45c4-9320-1059c045e48a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Davide Scatto

unread,
May 7, 2014, 10:08:40 AM5/7/14
to django...@googlegroups.com
Do you start from Ques model? What are your starting data?

Anushree Jangid

unread,
May 7, 2014, 10:19:49 AM5/7/14
to django...@googlegroups.com
No I start with subject model. There I have created subjects like General knowledge, English etc. ​Then I create question banks Like for General knowledge I have created GK1, GK2 and GK3 . Then when I enter a ques in the Ques model there I specify that the question is related to which subject and which question bank. 
For e.g In Ques model I enter
content=what is friction
subject=General knowledge
ques_bank=GK1


​Now for eg I want to know the question banks associated with subject​ General knowledge, then it should tell GK1 GK2 and GK3 
Assume all the questions related to the subjects along with their question banks have been stored in Ques model.


--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--
Anushree Jangid
BIT Mesra, Jaipur Campus

Rafael E. Ferrero

unread,
May 7, 2014, 10:58:21 AM5/7/14
to django...@googlegroups.com
You are using Ques for related Subject and QuestionBank... just make a method in Ques class who filter the Ques model with some subject parameter or do it in your view like:
   qs = Ques.objects.select_related().filter(subject='some_name')


I'm missing something really big? or i miss understud your question?



Anushree Jangid

unread,
May 7, 2014, 11:03:17 AM5/7/14
to django...@googlegroups.com
no no you are not missing anything. You got it right and I did that in view and it worked. Actually I am new to Django. Thanks a lot.





For more options, visit https://groups.google.com/d/optout.

Rafael E. Ferrero

unread,
May 7, 2014, 11:31:37 AM5/7/14
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages