-1

Django にあいまいなデータベースがあります。データベースは読み取り専用で、プロパティ管理ソフトウェアによって作成されます。基本的に、特定のレコードを取得するには、このクエリを作成する必要があると考えています。

SELECT * FROM propuserdefinedvalues WHERE propid = propid and userdefinedid = 49

生のSQLの代わりにこれを実行するDjangoの方法はありますか? 「プロパティ」テーブルをループしています。これらのレコードは「userdefinedcalues」テーブルにあります。

これが私のモデルです。

class Property(models.Model):
    propid = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=35L, blank=True)
    shortname = models.CharField(max_length=6L, blank=True)
    street1 = models.CharField(max_length=50L, blank=True)
    street2 = models.CharField(max_length=50L, blank=True)
    city = models.CharField(max_length=50L, blank=True)
    state = models.CharField(max_length=2L, blank=True)
    zip = models.CharField(max_length=50L, blank=True)
    phone = models.CharField(max_length=21L, blank=True)
    fax = models.CharField(max_length=50L, blank=True)
    email = models.CharField(max_length=255L, blank=True)
    manager = models.CharField(max_length=25L, blank=True)
    billname1 = models.CharField(max_length=35L, blank=True)
    billname2 = models.CharField(max_length=35L, blank=True)
    billstreet1 = models.CharField(max_length=50L, blank=True)
    billstreet2 = models.CharField(max_length=50L, blank=True)
    billcity = models.CharField(max_length=50L, blank=True)
    billstate = models.CharField(max_length=2L, blank=True)
    billzip = models.CharField(max_length=50L, blank=True)
    proptaxid = models.CharField(max_length=35L, blank=True)
    rentchargetype = models.CharField(max_length=20L, blank=True)
    lastpostdate = models.DateField(null=True, blank=True)
    lastweeklypostdate = models.DateField(null=True, blank=True)
    comments = models.CharField(max_length=25L, blank=True)
    enablespeciallatecharge = models.IntegerField(null=True, blank=True)
    fixedlatecharge = models.IntegerField(null=True, blank=True)
    fixedlateamount = models.FloatField(null=True, blank=True)
    fixedlaterentonly = models.IntegerField(null=True, blank=True)
    percentlate = models.IntegerField(null=True, blank=True)
    percentlateamount = models.FloatField(null=True, blank=True)
    percentlatefullcharge = models.IntegerField(null=True, blank=True)
    percentlaterentonly = models.IntegerField(null=True, blank=True)
    perdaylate = models.IntegerField(null=True, blank=True)
    perdaylateamount = models.FloatField(null=True, blank=True)
    perdaylategrace = models.IntegerField(null=True, blank=True)
    perdaylategracenum = models.IntegerField(null=True, blank=True)
    perdatelatelimitamount = models.FloatField()
    perdaylategracenonretro = models.IntegerField()
    perdaylategraceexclweekends = models.IntegerField()
    perdaylategraceexclholidays = models.IntegerField()
    datecreated = models.DateTimeField(null=True, blank=True)
    updated = models.DateTimeField(null=True, blank=True)
    userid = models.IntegerField(null=True, blank=True)
    logofile = models.CharField(max_length=255L, blank=True)
    merchantid = models.CharField(max_length=255L, blank=True)
    epaybankid = models.IntegerField()
    epaylimit = models.FloatField()
    epayenabled = models.IntegerField()
    achconveniencefeeenabled = models.IntegerField()
    ccconveniencefeeenabled = models.IntegerField()
    rwaachconvenciencefeeenabled = models.IntegerField()
    rwaccconveniencefeeenabled = models.IntegerField()
    epayislimited = models.IntegerField()
    epayusedefaults = models.IntegerField()
    achconveniencefee = models.FloatField(null=True, blank=True)
    ccconveniencefee = models.FloatField(null=True, blank=True)
    rwaachconveniencefee = models.FloatField(null=True, blank=True)
    rwaccconveniencefee = models.FloatField(null=True, blank=True)
    epaychargetype = models.IntegerField()
    epayamounttype = models.IntegerField()
    epaysetamount = models.FloatField()
    epaycustlimit = models.FloatField()
    sqft = models.IntegerField()
    lateminbalance = models.FloatField(null=True, blank=True)
    defaultbank = models.IntegerField()
    postday = models.IntegerField(null=True, blank=True)
    active = models.IntegerField(null=True, blank=True)
    iscommercial = models.IntegerField(null=True, blank=True)
    assignedissueuserid = models.IntegerField(null=True, blank=True)
    class Meta:
        db_table = 'property'

class Propuserdefined(models.Model):
    id = models.IntegerField(primary_key=True)
    userdefinedid = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=50L, blank=True)
    type = models.IntegerField()
    userid = models.IntegerField(null=True, blank=True)
    updated = models.DateTimeField(null=True, blank=True)
    datecreated = models.DateTimeField(null=True, blank=True)
    combolist = models.TextField(blank=True)
    class Meta:
        db_table = 'propuserdefined'

class Propuserdefinedvalues(models.Model):
    userdefinedid = models.ForeignKey(Propuserdefined)
    propid = models.ForeignKey(Property)
    value = models.TextField(blank=True)
    userid = models.IntegerField(null=True, blank=True)
    updated = models.DateTimeField(null=True, blank=True)
    datecreated = models.DateTimeField(null=True, blank=True)
    class Meta:
        db_table = 'propuserdefinedvalues'

これが私の見解です

def properties(request):
    properties = Property.objects.all().order_by('state')
    altname = SELECT * FROM propuserdefinedvalues WHERE propid = 73 and userdefinedid = 49
    return render_to_response('properties/index.html', {'properties':properties, }, context_instance=RequestContext(request))

これが私のテンプレートです

{% for property in properties %}
{{ altname }}<br><br>
{% endfor %}

よろしくお願いします。ブランドン

4

2 に答える 2