为什么django / tastypie与postgresql连接模型_?

时间:2013-11-25 05:22:14

标签: python django postgresql tastypie

我正在使用django和tastypie的postgresql。我已经为某些模型设置了我的模型和资源并使用mongodb,我正在尝试将postgresql用于关系数据模型。出于某种原因,当查询针对postgresql执行时,文件夹(模块)将连接到表名和所述模型的所有字段:

"error_message": "relation \"models_member\" does not exist\nLINE 1: ..._member\".\"dob\", \"models_member\".\"last_login\" FROM \"models_me...\n                                                             ^\n",

会员资源:

from api.models.member import Member
from django.conf.urls import url
from api.helper_methods import HelperMethods
from tastypie.resources import ModelResource
import json

class MemberResource(ModelResource):
    class Meta:
        max_limit = 0
        queryset = Member.objects.all().order_by('id')
        allowed_methods = ('get', 'post')
        resource_name = 'members'
        include_resource_uri = False

    def prepend_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/(?P<pk>[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('get_member'), name="api_get_member"),
        ]

    def get_member(self, request, **kwargs):
        member = Member.objects.get(id=kwargs['pk'])
        return self.create_response(request, member)

会员模特:

from tastypie.utils.timezone import now
from django.db import models

class Member(models.Model):
    id = models.IntegerField()
    fname = models.CharField()
    lname = models.CharField()
    addr1 = models.CharField()
    addr2 = models.CharField()
    city = models.CharField()
    state = models.CharField()
    zip = models.CharField()
    country = models.CharField()
    email = models.CharField()
    password = models.CharField()
    sex = models.CharField(max_length=6)
    dob = models.CharField()
    last_login = models.DateTimeField(default=now)

我如何告诉我的资源或...无论如何...说嘿,不要连接任何东西,只是打电话?我输了(并且是pythong / django / tastypie /上述所有内容的新手。)

1 个答案:

答案 0 :(得分:1)

Django为表名添加前缀,其中包含定义它们的应用程序的名称和下划线。您是手动创建了postgres中的表还是让django创建它?你可以通过在模型的meta中设置db_table来告诉django表的名称应该是什么。更多信息in the docs

class Member(models.Model):
    id = models.IntegerField()
    class Meta:
        db_table = 'member'