models

Ruby NoMethodError - undefined method `blah_url' for BlahController

余生长醉 提交于 2020-01-03 08:55:07
问题 I am calling this js from a link: function createNewTopLevelEntry(){ var user_id = $("#user").val(); var header = prompt("Enter the name"); $.ajax( '/users/' + user_id + '/entries', { data: { entry: { header: header, user: user_id } }, type: 'POST', cache: false, dataType: 'json', success: displayTopLevelEntries }); } It hits this controller: def create @entry = Entry.new(params[:entry]) respond_to do |format| if @entry.save format.html { redirect_to @entry, notice: 'Entry was successfully

django1.6之mysql配置

风格不统一 提交于 2020-01-02 04:57:47
# Database # https://docs.djangoproject.com/en/1.6/ref/settings/#databases setting 配置修改 INSTALLED_APPS = ( # 'django.contrib.admin', # 'django.contrib.auth', # 'django.contrib.contenttypes', # 'django.contrib.sessions', # 'django.contrib.messages', # 'django.contrib.staticfiles', 'xiaoji', ) DATABASES = { 'default': { 'ENGINE': 'mysql.connector.django', 'NAME':'test', 'USER':'root', 'PASSWORD':'root', 'HOST':'127.0.0.1', 'PORT':'3306', } } model类创建,在xiaoji包下创建models.py,内容如下: from django.db import models from django.utils.translation import ugettext_lazy as _ class product(models.Model): name =

django (python) 使用 models serializers views key_words

给你一囗甜甜゛ 提交于 2020-01-01 13:13:47
1. models from django.db import models class Test(models.Model): id = models.BigAutoField(primary_key=True, max_length=20) name = models.CharField(max_length=255, null=False, blank=False) value = models.TextField(db_column='value',null=False, blank=False) def __str__(self): reutrn self.name class Meta: db_table = 'test' #数据库名 2. serializers from rest_framework import serializers class TestSerializer(serializers.Serializer): id = serializers.IntegerField(read_only=True) name = serializers.CharField(read_only=True) value = serializers.CharField(read_only=True) 3. views from .models import Test

django accessing subclasses of models

无人久伴 提交于 2020-01-01 11:57:36
问题 I'm using subclasses in my django-models like this: class Person(models.Model): name = models.CharField(max_length=100) ... class Butcher(Person): ... class Driver(Person): ... In my view i want to do certain things depending on the subclass of the Person-class, like this: def person_detail_view(request, slug): person = Person.objects.get(slug=slug) if person.butcher: ... elif person.driver: ... But this gives me a DoesNotExist-Error when the Person is a Driver. Is there a way to ask the

Django empty field fallback

泄露秘密 提交于 2019-12-30 10:06:18
问题 I have a model that holds user address. This model has to have first_name and last_name fields since one would like to set address to a recipient (like his company etc.). What I'm trying to achieve is: if the fist_name/last_name field in the address is filled - return simply that field if the fist_name/last_name field in the address is empty - fetch corrresponding field data from a foreignkey pointing to a proper django.auth.models.User I'd like this to be treated as normal django field that

How to change Zend_Db_Table name within a Model to insert in multiple tables

江枫思渺然 提交于 2019-12-30 05:26:34
问题 Using Zend Framework, I've created a Model to insert a record into a database. My question is, after $this->insert($data) how can I switch the active table so that I can insert a record into another table? Here's my code so far: class Model_DbTable_Foo extends Zend_Db_Table_Abstract { protected $_name = 'foo'; public function addFoo($params) { $data = array( 'foo' => $params['foo'], ); $this->insert($data); $foo_id = $this->getAdapter()->lastInsertId(); $data2 = array( 'bar' => $params['bar']

如何快速的将离线语音识别PocketSphinx集成到自己的项目中

随声附和 提交于 2019-12-30 04:27:52
一、首先下载官方的DEMO 我给出我的链接让大家下载: PocketSphinx官方DEMO 二、自己新建一个AndroidStdio项目 三、导入官方项目的依赖aars具体步骤如下 然后点击next 然后打开自己工程的setting.grade 加入这句话include ‘:app’, ‘:models’, ‘:wear’, ‘:aars’, ‘:pocketsphinx-android-5prealpha-release’如下图所示: 然后点击右上角的Sync Now 然后你的项目中就会出现aars和models文件夹和库文件 然后将官方Demo中的aars文件夹和models文件夹中的内容分别拷贝到自己工程中的aars文件夹和models文件夹 四、将官方Demo中的assets文件夹中的内容拷贝到自己工程中的assets文件夹中,如果没有新建一个 五、将Demo中的MainActivity和layout中的内容复制到自己的工程中 六、在自己工程中的Build.gradle文件中 添加implementation project(’:aars’) 七、自己工程添加权限 <uses-permission android:name="android.permission.RECORD_AUDIO"/> 八、把自己的工程运行到自己的手机上就OK了 九、如果有问题联系我:QQ

zend modules models

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-29 09:08:30
问题 My application setup with 2 modules admin and default I test the controller which works fine on modules but the models doesnt work I created a model application\modules\admin\models\User.php <?php class Admin_Model_User{ } inside the controller $user = new Admin_Model_User(); Fatal error: Class 'Admin_Model_User' not found 回答1: Essentially, you need 2 lines in the application.ini file; resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" resources.modules[] = "" Then, for

Extending Eloquent Models in Laravel (use different tables)

扶醉桌前 提交于 2019-12-29 03:39:33
问题 I’m building a Laravel application that involves tracking different types of leads. For example, there are Refinance leads and Purchase leads . Since the leads share a lot of information and functionality, but not all, my thinking was to create a Lead class, which extends Laravel’s Model class, and then a RefinanceLead class, which extends the Lead class. So I’d have: class Lead extends Model { // shared lead stuff } class RefinanceLead extends Lead { // stuff specific to refinance leads } My

Django 后端admin设置

↘锁芯ラ 提交于 2019-12-28 11:27:38
1.在models中建表 2.admin中注册models中的对象 3.终端执行 (python) (base) bogon:aweb apple$ python manage.py shell Database version : 8.0.18 Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from datetime import datetime >>> from tea1.models import prac >>> prac.objects.all() <QuerySet []> >>> prac1 = prac(title='test',body='just see', timestamp=datetime.now()) >>> prac1 <prac: prac object (None)> >>> prac1.save() /Applications/anaconda3/python/lib/python3.7/site-packages