Re: how to model a reflexive many to many relationship?

2013-08-28 Thread slim


This is my progress so far :

class Utilisateur(models.Model):
user   = models.OneToOneField(User)
role   = models.CharField(choices=ROLES,blank=False,max_length=50)
managed_by = models.ManyToManyField('self', 
 related_name='managers',
 symmetrical=False, 
 blank=True)
course = models.ManyToManyField('Course')   #can I do it? (question 2)
module = models.ManyToManyField('Module', through='UtilisateurModule')

class Course(models.Model):
titre  = models.CharField(blank=False,max_length=100)
class Module(models.Model):
titre = models.CharField(blank=False,max_length=100)
course= models.ManyToManyField(Course, through='ModuleCourse')
class ModuleCourse (models.Model):
module = models.ForeignKey(Module)
course = models.ForeignKey(Course)
order  = models.IntegerField(blank=False)   

class UtilisateurModule (models.Model):
user   = models.ForeignKey(Utilisateur)
module = models.ForeignKey(Module)
score  = models.IntegerField(blank=False)

My questions :

*1*. How to get the scores of a user by module and display them by course, 
like that :

-Course A

 *Module 1 

   score : 5

 *module 2 :

  score : 8

 ...
-Course B

 *Module 1:

   score 7

 

*2*. I need to add a many to many relationship between course and user 
because I wouldnt tell which course affected to which user only by 
affecting a module to him knowing that the module can belong to several 
courses, is it correct to add a parcours = 
models.ManyToManyField('Parcours') in Utilisateur?
Help me please

Thanks

Le lundi 26 août 2013 12:06:24 UTC+1, slim a écrit :
>
> I'm trying to build an e-learning platform
> I have *users (Utilisateur) *who can take several *courses* ,each course 
> have several *modules* and a module can be in several courses
> a user can be a student or teacher or admin, a student is "managed" by a 
> teacher or several and a teacher can also  be managed by a teacher (if he 
> is a researcher) ,teachers are managed by admins
>
> this is my conception :
>
>
> 
>
> I'm not familiar with many_to_many and through concept, please correct me
>  this is my django models :
>
> class Utilisateur(models.Model):
> user   = models.OneToOneField(User)
> role   = models.CharField(choices=ROLES,blank=False,max_length=50)
> managed_by = models.ManyToManyField('self', 
> through='UtilisateurRelationship', symmetrical=False, blank=True)
> 
> 
> class UtilisateurRelationship(models.Model):
> managed = models.ForeignKey(Utilisateur)
> manager = models.ForeignKey(Utilisateur)
> 
> 
>
> class Course(models.Model):
> titre  = models.CharField(blank=False,max_length=100)
> 
> class ModuleCourse (models.Model):
> module = models.ForeignKey(Module)
> course = models.ForeignKey(Course)
> order  = models.IntegerField(blank=False)   
> 
> class Module(models.Model):
> titre = models.CharField(blank=False,max_length=100)
> belong_to = models.ManyToManyField(Course, through='ModuleCourse')
> 
> class UtilisateurModule (models.Model):
> user   = models.ForeignKey(Utilisateur)
> module = models.ForeignKey(Module)
> score  = models.IntegerField(blank=False)
> 
>   
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: how to model a reflexive many to many relationship?

2013-08-28 Thread Wissal Wbc
This is my progress so far :


class Utilisateur(models.Model):
user   = models.OneToOneField(User)
role   = models.CharField(choices=ROLES,blank=False,max_length=50)
managed_by = models.ManyToManyField('self',
 related_name='managers',
 symmetrical=False,
 blank=True)
course = models.ManyToManyField('Course')   #can I do it? (question 2)
module = models.ManyToManyField('Module', through='UtilisateurModule')

class Course(models.Model):
titre  = models.CharField(blank=False,max_length=100)
class Module(models.Model):
titre = models.CharField(blank=False,max_length=100)
course= models.ManyToManyField(Course, through='ModuleCourse')
class ModuleCourse (models.Model):
module = models.ForeignKey(Module)
course = models.ForeignKey(Course)
order  = models.IntegerField(blank=False)

class UtilisateurModule (models.Model):
user   = models.ForeignKey(Utilisateur)
module = models.ForeignKey(Module)
score  = models.IntegerField(blank=False)

*My questions :*

*1*. How to get the scores of a user by module and display them by course,
like that :

-Course A

 *Module 1

   score : 5

 *module 2 :

  score : 8

 ...
-Course B

 *Module 1:

   score 7

 

*2*. I need to add a many to many relationship between course and user
because I wouldnt tell which course affected to which user only by
affecting a module to him knowing that the module can belong to several
courses, is it correct to add a parcours =
models.ManyToManyField('Parcours') in Utilisateur?



2013/8/26 slim 

> I'm trying to build an e-learning platform
> I have *users (Utilisateur) *who can take several *courses* ,each course
> have several *modules* and a module can be in several courses
> a user can be a student or teacher or admin, a student is "managed" by a
> teacher or several and a teacher can also  be managed by a teacher (if he
> is a researcher) ,teachers are managed by admins
>
> this is my conception :
>
>
> 
>
> I'm not familiar with many_to_many and through concept, please correct me
>  this is my django models :
>
> class Utilisateur(models.Model):
> user   = models.OneToOneField(User)
> role   = models.CharField(choices=ROLES,blank=False,max_length=50)
> managed_by = models.ManyToManyField('self',
> through='UtilisateurRelationship', symmetrical=False, blank=True)
>
>
> class UtilisateurRelationship(models.Model):
> managed = models.ForeignKey(Utilisateur)
> manager = models.ForeignKey(Utilisateur)
>
>
>
> class Course(models.Model):
> titre  = models.CharField(blank=False,max_length=100)
>
> class ModuleCourse (models.Model):
> module = models.ForeignKey(Module)
> course = models.ForeignKey(Course)
> order  = models.IntegerField(blank=False)
>
> class Module(models.Model):
> titre = models.CharField(blank=False,max_length=100)
> belong_to = models.ManyToManyField(Course, through='ModuleCourse')
>
> class UtilisateurModule (models.Model):
> user   = models.ForeignKey(Utilisateur)
> module = models.ForeignKey(Module)
> score  = models.IntegerField(blank=False)
>
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/SCS2oMa0P-M/unsubscribe.
> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


how to model a reflexive many to many relationship?

2013-08-26 Thread slim
I'm trying to build an e-learning platform
I have *users (Utilisateur) *who can take several *courses* ,each course 
have several *modules* and a module can be in several courses
a user can be a student or teacher or admin, a student is "managed" by a 
teacher or several and a teacher can also  be managed by a teacher (if he 
is a researcher) ,teachers are managed by admins

this is my conception :



I'm not familiar with many_to_many and through concept, please correct me
 this is my django models :

class Utilisateur(models.Model):
user   = models.OneToOneField(User)
role   = models.CharField(choices=ROLES,blank=False,max_length=50)
managed_by = models.ManyToManyField('self', 
through='UtilisateurRelationship', symmetrical=False, blank=True)


class UtilisateurRelationship(models.Model):
managed = models.ForeignKey(Utilisateur)
manager = models.ForeignKey(Utilisateur)


   
class Course(models.Model):
titre  = models.CharField(blank=False,max_length=100)

class ModuleCourse (models.Model):
module = models.ForeignKey(Module)
course = models.ForeignKey(Course)
order  = models.IntegerField(blank=False)   

class Module(models.Model):
titre = models.CharField(blank=False,max_length=100)
belong_to = models.ManyToManyField(Course, through='ModuleCourse')

class UtilisateurModule (models.Model):
user   = models.ForeignKey(Utilisateur)
module = models.ForeignKey(Module)
score  = models.IntegerField(blank=False)

  

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.