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 :
>
>
> <https://lh5.googleusercontent.com/-0IKqEtcoluA/Uhs2f2Mqh9I/ACg/chYFCfSIIeM/s1600/elearning_model.png>
>
> 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.


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.


Django admin error : coercing to Unicode: need string or buffer, NoneType found

2013-04-24 Thread slim
Hello everyone,

I have this error since a long time but can't figure it out :

*Caught TypeError while rendering: coercing to Unicode: need string or 
buffer, NoneType found*

It happens in admin when I try to add or modify on one of my models 
(display works fine)


This is the model:


class PS(models.Model):
id_ps = models.IntegerField(null=True)
client = models.ForeignKey(Client, null=True, blank=True)
nom_du_site = models.CharField(max_length=250)
rue_livraison = models.TextField(null=True)
complement_adresse = models.TextField(null=True)
code_postal_livraison = models.CharField(max_length=50, null=True)
ville_livraison = models.CharField(max_length=200, null=True)
pays_livraison = models.CharField(max_length=200, null=True)
distributeur = models.CharField(max_length=50, null=True)
tarif = models.CharField(max_length=250, null=True)
type_tarif = models.CharField(max_length=50, null=True)
type_installation = models.CharField(max_length=50, null=True)

def __unicode__(self):
return self.nom_du_site

@property
def pce(self):
try:
return PCE.objects.filter(ps=self)[0]
except IndexError:
return
#
def get_pce(self):
from pce.models import PCE
return PCE.objects.filter(ps=self).exclude(frequence='6M')
#
def get_pce_6m(self):
from pce.models import PCE
return PCE.objects.filter(ps=self,frequence='6M') 



Any idea what am i doing wrong here?


*Traceback:*

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8026/admin/ps/ps/add/
Django Version: 1.2.5
Python Version: 2.7.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.admin',
 'easy_thumbnails',
 'django_extensions',
 'contentadmin',
 'south',
 'sentry',
 'sentry.client',
 'indexer',
 'file_uploader',
 'paging',
 'pagination',
 'consommation',
 'ps',
 'pce',
 'profil',
 'analytics',
 'document']
Installed Middleware:
('annoying.middlewares.StaticServe',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'pagination.middleware.PaginationMiddleware')


Template error:
In template 
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/includes/fieldset.html,
 
error at line 19
   Caught TypeError while rendering: coercing to Unicode: need 
string or buffer, NoneType found
   9 : {% for field in line %}


   10 : 


   11 : {% if not line.fields|length_is:'1' and 
not field.is_readonly %}{{ field.errors }}{% endif %}


   12 : {% if field.is_checkbox %}


   13 : {{ field.field }}{{ field.label_tag 
}}


   14 : {% else %}


   15 : {{ field.label_tag }}


   16 : {% if field.is_readonly %}


   17 : {{ field.contents }}


   18 : {% else %}


   19 :   *   {{ field.field }} *


   20 : {% endif %}


   21 : {% endif %}


   22 : {% if field.field.field.help_text %}


   23 : {{ 
field.field.field.help_text|safe }}


   24 : {% endif %}


   25 : 


   26 : {% endfor %}


   27 : 


   28 : {% endfor %}


   29 : 


Traceback:
File 
"/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in 
get_response
  100. response = callback(request, 
*callback_args, **callback_kwargs)
File 
"/usr/local/lib/python2.7/dist-packages/django/contr

Re: django search

2013-04-15 Thread slim
add try and catch to your request

Le samedi 13 avril 2013 15:59:49 UTC, Harjot Mann a écrit :
>
> hello friends 
>
> i have made a project on studnt dmc records in django...in which i search 
> for student' s dmcs using roll number..it works fine
> but the problem is that when i am typing a fake roll number which is not 
> existing..it is showing me an error like given in the pic
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How do I display image in admin list?

2013-04-15 Thread slim

in your model create a function

*def admin_photo(self):*
*return '' % self.photo.url*
*admin_photo.allow_tags = True*

then just add it in the display list :

*class MymodelAdmin(admin.ModelAdmin):*
*list_display = (...,'photo')  *
*admin.site.register(Mymodel, MymodelAdmin)*



Le mardi 9 avril 2013 11:33:43 UTC, frocco a écrit :
>
> Hello,
>
> I have a standard image field in my model, and want to see the images on 
> the admin list page.
>
> how do I modify admin.py to do this?
>
> Thanks
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




how to copy a cart session

2013-03-25 Thread slim

Hello everyone,


I have an e-commerce site
A user arrives  without first logging in, adds a few things to their cart, 
 a session is established for this user, and then proceeds to the checkout. 
the command is then saved in database.

Now I need the user to log in and see their recent commands,untill now no 
probleme (at least at first sight) but the user want to "duplicate" one of 
their recent commands put it in the current cart then modify on it if 
necessary before checkout

I have absolutely no idea how to do that :/

If possible,I need a quick answer on the complexity of doing it and how 
much time I need so I can go back to my boss
then any clues to help me do that would be greatly appreciated

Thanks in advance

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.