Ejemplo n.º 1
0
def parseModelSql():
    from django.db import connection, transaction
    cursor = connection.cursor()
    makes = list(Make.objects.all())
    
    for make in makes:
        cursor.execute("SELECT DISTINCT model FROM web_carclassified WHERE make = '" + str(make.make) + "'")
        models = cursor.fetchall()
        for model in models:
            modelname = str(model[0]).replace("'", "''") #Escape apostrophe, Kia Cee'd :)
            _model = Model()
            _model.make = make
            _model.model = modelname
            cursor.execute("SELECT count(*) FROM web_carclassified WHERE model = '" + modelname + "' AND make = '" + make.make + "'")
            _model.count = int(cursor.fetchone()[0]) 
            _model.save()
Ejemplo n.º 2
0
def parseMakeModel():
    makes = CarClassified.objects.all()
    makes = uniquify(makes)  
    for _make in makes:
        make = Make()
        make.make = _make.make
        make.count = len(CarClassified.objects.all().filter(make=_make.make))
        make.save()
        
        models = CarClassified.objects.all().filter(make=_make.make)
        models = uniquify(models)
        for _model in models:
            model = Model()
            model.model = _model.model
            model.make = make
            model.count = len(CarClassified.objects.all().filter(model=model.model))
            model.save()