有没有办法modelData从视图委托(特别是中继器)访问。
我尝试使用单独的属性并尝试通过它访问它,model.modelData但这都不起作用。
请参阅下面的代码快照。
提前致谢。
Component
{
id: comp_1
Rectangle
{
color: "green"
width: 200
height: 200
}
}
Component
{
id: comp_2
Rectangle
{
color: "red"
width: 200
height: 200
Text
{
anchors.fill: parent
text: modelData
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
}
function getDelegate(itemName)
{
if(itemName === "comp1")
return comp_1;
else
return comp_2;
}
Row
{
Repeater
{
id: repeat
model: ["comp1", "comp2"]
Loader
{
sourceComponent: getDelegate(modelData)
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 Laravel 5.2 开发 web 应用程序,但有一个我无法解决的问题。
我有一个扩展 Eloquent 模型的模型,但是当我尝试使用“where”输出我的数据库表时,例如
\App\MyModel::where('id_table', 23)->first();
Run Code Online (Sandbox Code Playgroud)
它返回一个包含许多目前对我无用的信息的集合,例如“受保护”、“密钥类型”……并且我的表的数据位于“属性”下。按照laravel的指南,我看到每个人都像我一样简单地使用 where 然后用 输出$mytable->myvalue,但这当然对我不起作用。
这是我正在谈论的集合的屏幕截图:
当我使用类似的东西时,我怎么能总是得到属性"::where()"?
我试过了,getAttributes()但它给了我 500 错误。
我正在尝试运行查看和操作一个简单的 django 数据库,但是 Django Shell 的错误是说我的模型之一未定义。
大多数与我的错误类似的问题是由于人们在声明模型之前引用了模型。但是,我没有在Album 中引用任何其他模型。
模型.py
from __future__ import unicode_literals
from django.db import models
class Album(models.Model):
artist = models.CharField(max_length=250)
title = models.CharField(max_length=500)
genre = models.CharField(max_length=100)
logo = models.CharField(max_length=1000)
class Song(models.Model):
album = models.ForeignKey(Album, on_delete=models.CASCADE)
file_type = models.CharField(max_length=10)
title = models.CharField(max_length=250)
Run Code Online (Sandbox Code Playgroud)
我得到的错误: NameError: name 'Album' is not defined
知道这个错误的原因是什么吗?
作为参考,我在下面thenewboston是Django的教程在这里。
我的环回应用程序中有一个持久模型,我想相应地自动添加createdAt和updatedAt属性为此模型实例。实现这一目标的简单方法是什么?
我有这个模型连接到 SQLSERVER 数据库,使用一个插件,允许我从数据库生成我的模型。但是在尝试访问视图时出现此错误。
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CuentasBancarias extends Model
{
protected $table = 'CUENTASBANCARIAS_GRUPO7F';
protected $primaryKey = 'idcuentasbancarias';
protected $incrementing = false;
protected $fillable = ['idcuentasporcobrar', 'idcuentaporpagar', 'nombre_banco', 'nro_cuenta', 'titular_cuenta', 'fecha', 'total_deposito', 'total_retiro', 'Id_CLIENTES', 'Id_COMPRAS', 'Id_PROVEEDORES', 'id_VENTAS', 'Estado'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function cuentasporcobrarGRUPO7F()
{
return $this->belongsTo('App\CuentasporcobrarGRUPO7F', 'idcuentasporcobrar', 'idcuentasporcobrar');
}
public function cuentasporpagarGRUPO7F()
{
return $this->belongsTo('App\CuentasporpagarGRUPO7F', 'idcuentaporpagar', 'idcuentaporpagar');
}
public function sUBCUENTASGRUPO9s()
{
return $this->hasMany('App\SUBCUENTASGRUPO9', 'idcuentasbancarias', 'idcuentasbancarias');
}
Run Code Online (Sandbox Code Playgroud)
}
我收到以下错误:
AttributeError: Got AttributeError when attempting to get a value for field `city` on serializer `SearchCitySerializer`
Run Code Online (Sandbox Code Playgroud)
我的序列化程序是正确的,除非我明显遗漏了一些东西。
这是我的模型:
class SearchCity(models.Model):
city = models.CharField(max_length=200)
Run Code Online (Sandbox Code Playgroud)
这是我的序列化程序
class SearchCitySerializer(serializers.ModelSerializer):
class Meta:
model = SearchCity
fields = ('pk','city')
Run Code Online (Sandbox Code Playgroud)
*** 我在没有 pk 的情况下尝试了序列化程序,但仍然失败
在这里它在视图中使用:
from serializers import SearchCitySerializer
def get(self, request, format=None):
searchcityqueryset = SearchCity.objects.all()
serializedsearchcity = SearchCitySerializer(searchcityqueryset)
return Response({
'searchcity': serializedsearchcity.data,
})
Run Code Online (Sandbox Code Playgroud)
我得到的完整错误:
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/suitsandtables/suitsandtablessettingsapp/views.py", line 37, in get
'searchcity': serializedsearchcity.data,
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 537, in data
ret = super(Serializer, self).data
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/local/lib/python2.7/site-packages/rest_framework/serializers.py", line …Run Code Online (Sandbox Code Playgroud) django serialization model attributeerror django-rest-framework
如果我想说实话,我不知道 android 或 java 中的任何集合的工作,但是我的问题和我的目的,我想删除我的模型或我的类的 ArrayList 中的重复项,这是我的模型,如下所示:
public class PersonClass {
private String ID;
private String Name;
private String Family;
private String Nickname;
private String Email;
private String Mobile;
private Date BirthDate;
private boolean Admin;
private boolean Gender;
private String ThumbnailURL;
public PersonClass() {
}
public PersonClass(String ID, String name, String family, String nickname, String email, String mobile, Date birthDate, boolean admin, boolean gender, String thumbnailURL) {
this.ID = ID;
Name = name;
Family = family;
Nickname = nickname;
Email …Run Code Online (Sandbox Code Playgroud) 我有两个表(模型)被调用Users,Books并且需要为我的表创建自定义 ID(主键)值,比如u25894r用户和b419k书籍。我在互联网和 stackoverflow 上搜索了很多,但我不明白我应该在哪里定义我的自定义 ID 生成器函数,例如,AppServiceProvider boot function或者在Model constructor函数中。如果你用一个小例子来说明方法,我会非常感激。
编辑:我需要编写为表生成唯一自定义 ID 的函数。
我需要在我的模型中设置默认的 where 条件。
所以实际上我必须在我的所有选择查询中设置它。
查询如:
->where('status','active')
Run Code Online (Sandbox Code Playgroud) 在我的 models.py 文件中添加了一个 author 字段后,我试图进行迁移,但 Django 问我这个:
You are trying to add a non-nullable field 'author' to entry without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Run Code Online (Sandbox Code Playgroud)
我的 Models.py 文件:
from django.db import models
from django.utils import timezone
from django.urls …Run Code Online (Sandbox Code Playgroud) model ×10
eloquent ×4
laravel ×4
django ×3
python ×2
android ×1
attributes ×1
class ×1
collections ×1
database ×1
default ×1
duplicates ×1
javascript ×1
loopbackjs ×1
mysql ×1
node.js ×1
php ×1
qml ×1
qt ×1
repeater ×1
view ×1