我有一个问题,序列化ORM关系只显示前两个记录.其余只显示[]空白.
这是一个示例关系:
property name="endorsements" singularname="endorsement" fieldtype="one-to-many" lazy="false" fkcolumn="xxx" cfc="endorsements" remotingfetch="true";
Run Code Online (Sandbox Code Playgroud)
获得JSON:
policy = entityLoad("policy",1018379202)[1];
serializeJSON( policy );
Run Code Online (Sandbox Code Playgroud)
并减少了JSON的一部分:
{"id":12321,"endorsements":[{"effectiveDate":"July, 01 2009 00:00:00","active":true},
{"effectiveDate":"July, 01 2009 00:00:00","active":true},
"","","","","","","","",""]}
Run Code Online (Sandbox Code Playgroud)
空字符串应该是关系中的其他记录.
我已经通过调试文件验证了Hibernate查询带回了所有记录,cfdump也显示了这一点.
思考?
property name="poiLat" length="60" ormtype="big_decimal" persistent=true precision="16" scale="14" default="0" hint="";
Run Code Online (Sandbox Code Playgroud)
我不正确地理解精度或比例.使用上面的属性为什么'1'会出错并且'2'被接受?应该怎么做才能接受'1'
1)-118.27 =错误
2)-18.27 =好的
最后一件事我对Django Rest Framework有点困惑,而且权限类和身份验证类之间存在差异.
这是我的settings.py
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAdminUser',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'PAGINATE_BY': 10
Run Code Online (Sandbox Code Playgroud)
}
在我看来,我有以下......
class ProfileList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of users.
"""
permission_classes = (permissions.IsAdminUser,)
model = Profile
serializer_class = ProfileSerializer
def pre_save(self, obj):
obj.owner = self.request.user
Run Code Online (Sandbox Code Playgroud)
我上面假设的是,只有管理员用户才能访问可浏览的API,而具有有效令牌的用户仍然可以获得json请求.但是,情况并非如此,只有IsAuthenticated似乎给他们访问但是=这仍然允许我的用户在登录时访问在线版本.
我希望所有拥有有效令牌的用户都可以访问,但只有管理员用户才有权查看带有会话的在线API版本,这可能吗?
使用以下代码行:
from datetime import date
self.date_start_processing = date.now()
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
AttributeError:类型对象'datetime.date'没有属性'now'
我怎么解决这个问题?
谢谢.
我收到下面的错误,错误只发生在我添加delay到 process_upload函数时,否则它没有问题.
有人可以解释这个错误是什么,为什么会发生这种错误以及要解决的任何建议?
错误:
PicklingError at /contacts/upload/configurator/47/
Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
Run Code Online (Sandbox Code Playgroud)
这是观点
if request.method == 'POST':
form = ConfiguratorForm(data=request.POST)
# Send import to task.
process_upload.delay(upload_id=upload.id, form=form)
Run Code Online (Sandbox Code Playgroud)
这是任务
@task
def process_upload(upload_id, form):
upload = Upload.objects.get(id=upload_id)
upload.process(form=form)
Run Code Online (Sandbox Code Playgroud)
Upload.process在我的模型中:
def process(self, form):
self.date_start_processing = timezone.now()
import_this(data=self.filepath, extra_fields=[
{'value': self.group_id, 'position': 5},
{'value': self.uploaded_by.id, 'position': 6}], form=form)
Run Code Online (Sandbox Code Playgroud)
完整跟踪:
Traceback:
File "/Users/user/Documents/workspace/sms/django-env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/user/Documents/workspace/sms/django-env/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
25. return view_func(request, *args, …Run Code Online (Sandbox Code Playgroud) 我有一个模型方法,要求请求用户作为额外参数传入:
模型方法:
def has_achieved(self, user):
return AwardLog.objects.filter(user=user, badge=self).count() > 0
Run Code Online (Sandbox Code Playgroud)
使用Django Rest Framework我想调用这个put不知道如何传递来自Serializer的额外参数:
class BadgeSerializer(serializers.ModelSerializer):
achieved = serializers.SerializerMethodField(source='has_achieved(request.user???)')
class Meta:
model = Badge
fields = ("name", "achieved")
Run Code Online (Sandbox Code Playgroud)
我无法在任何地方找到这种情况.我的视图中是否有一个方法可以覆盖以传递并使用?谢谢.
我需要重新保存我所有的模型
Users.objects.all().update(active=True)
在模型中:
def save(self, *args, **kwargs):
self.url = "XYZ"
super(User, self).save(*args, **kwargs)
Run Code Online (Sandbox Code Playgroud)
但是,以上不会触发save()这些模型上的方法。所以没有设置 url = XYZ 。这可能吗?
更新:
看起来我不能使用 .update() 来做到这一点我试过这个:
>>> objects = Users.objects.all()
>>> for item in objects:
... item.save()
Run Code Online (Sandbox Code Playgroud) 在我的admin.py中,我使用'active'和'country'进行过滤,这是使用我的SomethingAdmin类中的以下代码行完成的....
list_filter = ['active', 'countryid']
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,在我的管理列表视图中显示countryid并不漂亮,如何将其更改为更友好的名称,比如说'Country'?
谢谢.
更新: 下面似乎工作:
incentiveid = models.ForeignKey(Incentive,verbose_name="Incentive",
null=True, db_column='incentiveID', blank=True)
Run Code Online (Sandbox Code Playgroud) 我正在使用ui-router,我正在尝试使视图转换工作,即动画视图更改.我试过的是下面的内容,但我没有看到关于视图更改的动画,为什么?
HTML:
载入中...
我的js的相关部分:
// Initialize the main module
app.run(['$rootScope', '$location', '$window', function ($rootScope, $location, $window) {
'use strict';
/**
* Helper method for main page transitions. Useful for specifying a new page partial and an arbitrary transition.
* @param {String} path The root-relative url for the new route
* @param {String} pageAnimationClass A classname defining the desired page transition
*/
$rootScope.go = function (path, pageAnimationClass) {
if (typeof(pageAnimationClass) === 'undefined') { // Use a default, your choice
$rootScope.pageAnimationClass = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Django Rest Framework 进行PATCH请求,但是收到以下错误:
{"image_data": [{"non_field_errors": ["Invalid data"]}]
Run Code Online (Sandbox Code Playgroud)
我知道JSONField()可以提供一些问题所以我通过添加 to_native和处理from_native了这个问题,但是,我仍然遇到了这个问题.我根本不认为这JSONField()是问题,但仍值得一提.
我相信我在尝试更新相关领域方面做了一些根本性的错误.
代码如下......
楷模:
class Photo(models.Model):
user = models.ForeignKey(AppUser, help_text="Item belongs to.")
image_data = models.ForeignKey("PhotoData", null=True, blank=True)
class PhotoData(models.Model):
thisdata = JSONField()
Run Code Online (Sandbox Code Playgroud)
串行器:
class ExternalJSONField(serializers.WritableField):
def to_native(self, obj):
return json.dumps(obj)
def from_native(self, value):
try:
val = json.loads(value)
except TypeError:
raise serializers.ValidationError(
"Could not load json <{}>".format(value)
)
return val
class PhotoDataSerializer(serializers.ModelSerializer):
thisdata = ExternalJSONField()
class Meta:
model = PhotoData
fields = ("id", "thisdata")
class …Run Code Online (Sandbox Code Playgroud) django ×7
python ×6
coldfusion ×2
coldfusion-9 ×2
angularjs ×1
django-orm ×1
javascript ×1
orm ×1