Hm... there is no relation to the user? So you are trying to group by name, surname and then count all individual courses? There is a high risk, that the user has a typo in his name or the courses name, than they would appear twice in the list. Is this your intention?
I'd rather do it like this
class User(Model):
...user fields...
class Course(Model):
name=CharField...
users = models.ManyToManyField(User)
...course fields...
class Egitim(models.Model):
user = ForeignKey(User)
course = ForeignKey(Course)
Then it is possible to do this:
User.objects.all().annotate(num_of_courses_taken=Count(course))
Have a look at this tutorial, it explains everything
Am Sonntag, 28. Juli 2013 14:16:08 UTC+2 schrieb Murat Bilal:
--Hi all,I have a model like this,class Egitim(models.Model):
name = models.CharField(max_length=200)
surname = models.CharField(max_length=20)
email = models.EmailField(max_length=75)
course_name = models.CharField(max_length=300)
num_of_courses_taken = models.IntegerField(max_length=100)
def __unicode__(self):return self.course_name
class EgitimForm(ModelForm):class Meta:
model=Egitim
fields=('name','surname','email','course_name')
I want to make num_of courses_taken by a special user.when the form is submittedFor ex:Emai...@aa.com num_of_courses_taken=12Please 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+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.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment