Bonjour à tous,

Je débute avec App Engine, Django et Python !! Tout d'un coup, ça fait beaucoup mais bon, j'ai pas trop le choix...
J'ai un problème avec une de mes views :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
@csrf_exempt
def get_establishments(request, user_id):
    try:
        _establishment = Establishment.objects.all()                               
        json_data = '{"establishments": ' + json.dumps(_establishment) + '}'           
        #json_data = '{"establishments": [{"id":1,"lat":10,"lng":10,"type":"village"},{"id":2,"lat":20,"lng":20,"type":"ville"},{"id":3,"lat":30,"lng":30,"type":"ville"}]}' #' + json.dumps(_ugas) + '
 
        return HttpResponse(json_data.encode('utf8'), content_type='application/json; charset=utf-8')
 
    except Exception, exception:
        return utility.create_http_error_response(exception.message)
Quand je suis en mode debug (sous eclipse), la variable _establishment est à "Unable to get repr for <class 'django.db.models.query.QuerySet' puis passe à QuerySet[]. Une exception est retournée lorsque json.dumps(_establishment) est exécuté. J'ai aussi tenté avec _establishment = Establishment.objects.count() : le nombre d'enregistrements correspondant à ma table est bien retourné.

Voici le modèle utilisé:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Establishment(models.Model):
    id =  models.AutoField(primary_key=True)
 
    lat = models.FloatField()
    lng = models.FloatField()    
    coro = models.BooleanField()
    ugazone =  models.ForeignKey(UGAzone)
    postalCode = models.CharField(max_length=5)
    commune = models.CharField(max_length=200)
 
    performance = models.URLField(max_length=200)
 
    establishments = models.ManyToManyField('self', symmetrical=False, through='PatientCircuit')
    protocol = models.ForeignKey(Protocol)    
 
    def as_dict(self):   
        return dict(id=self.id, lat=self.lat, lng=self.lng)  
 
    def as_json(self):
        return json.dumps(self.as_dict())
 
    def __unicode__(self):
        return self.id
Pourriez-vous m'aider à comprendre mon problème? Merci d'avance !!