I am using the following models in my django application and want to query across multiple fields. I looked around different places but couldnt find out what i exactly need.
class Attempt(models.Model, object):
'''Creates an Attempt Entity which is a subclass of models.Model class'''
attemptID_f = models.AutoField(primary_key=True)
questionID_f = models.ForeignKey(Question, verbose_name="Question", null=False)
userID_f = models.ForeignKey(User, verbose_name="User ID", null=False)
solution_f = models.TextField("Solution uploaded by the User", null=False)
errorReportID_f = models.ForeignKey(ErrorReport,verbose_name="Error Report for the Solution", null=True)
status_f = models.BooleanField("Status of attempt - true = right, false = wrong", blank=True, default=False)
timeOfSubmission_f = models.DateTimeField("Time of Submission", null=False)
compilerVersion_f = models.ForeignKey(CompilerVersion, verbose_name = "Compiler version of the Attempt",null=False)
class Question(models.Model, object):
'''Creates the entity question
which is a subclass of models.Model'''
questionID_f = models.AutoField(primary_key=True)
questionText_f = models.TextField("Problem Statement", null=False)
questionTitle_f = models.CharField("Problem Title", max_length = 50, null = False)
level_f = models.ForeignKey(Level, verbose_name="Question Level", null=False)
type_f = models.ForeignKey(Type, verbose_name="Type of Question", null=False)
timeLimit_f = models.FloatField("Time Limit for Question",null=False)
class Type(models.Model):
'''Creates the entity Type which is a subclass of models.Model class'''
typeID_f = models.AutoField(primary_key=True)
typeName_f = models.CharField("Type Name" , max_length = 30 , null = False)
typesm = Attempt.objects.filter(userID_f = request.user).values('attempt__questionID_f__type_f__typeID_f')
Is attempt__questionID_f__type_f__typeID_f a valid arguement if I want to reference the typeID_f field of type MODEL, which is referenced by type_f field of Question Model, which is referenced by questionID_f field of Attempt Model ?
Any help would be appreciated.
Thanks,
Pankaj.
Should be:
I’m not sure why you put the
attempt__prefix there when you are querying theAttemptmodel.See: Lookups that span relationships