在引入新应用程序(django-allauth)后执行迁移时出现错误.我不知道还有什么可以尝试以修复错误.我尝试了一些东西,但不幸的是它们似乎没有帮助.
运行manage.py migrate时:
File "D:\Python27\Lib\site-packages\django\db\migrations\state.py", line 71,
in render raise
InvalidBasesError("Cannot resolve bases for %r\nThis can happen if you are inheriting
models from an app with migrations (e.g. contrib.auth)\n in an app with no migrations;
see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more" %
new_unrendered_models)
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for
[<ModelState: 'blog.BlogPage'>, <ModelState: 'blog.BlogIndexPage'>]
This can happen if you are inheriting models from an app with migrations
(e.g. contrib.auth) in an app with no migrations; see
https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more
Run Code Online (Sandbox Code Playgroud)
models.py
from django.db …Run Code Online (Sandbox Code Playgroud) 不知道这是怎么回事。我正在尝试通过Django-rest-framework创建一个新实例。我究竟做错了什么?
提交了一些只读字段。我尝试通过read_only_fields序列化器将它们标记为只读,并editable=False在模型的字段中指定它们。
注意:如果可能,我宁愿避免指定自己的create方法。这应该通过此处记录的标准功能起作用
发布以下内容时:
{
"displayName": "New test",
"backgroundColour": "#4d3567",
"foregroundColour": "#FFFFFF",
"helpText": "test",
"description": "test",
"comment": "test."
}
Run Code Online (Sandbox Code Playgroud)
我越来越:
TypeError at /api/v1/classifications/
Got a `TypeError` when calling `ClassificationLabel.objects.create()`. This may be because you have a writable field on the serializer class that is not a valid argument to `ClassificationLabel.objects.create()`. You may need to make the field read-only, or override the ClassificationLabelListSerializer.create() method to handle this correctly.
Run Code Online (Sandbox Code Playgroud)
models.py:
class ClassificationLabel(models.Model):
"""
this …Run Code Online (Sandbox Code Playgroud) 我试图返回特定于用户的单个对象(不是查询集)而不必在请求的URL中指定标识符/ pk.每个用户都有一个组织FK.
即http://网站/组织,而不是http:// website/organization/1
我收到以下错误,因为它期望这个标识符:
AssertionError: Expected view OrganisationDetail to be called with a URL keyword argument named "user__organisation_id". Fix your URL conf, or set the.lookup_fieldattribute on the view correctly.
在使用RetrieveModelMixin/GenericAPIView时,如何/我需要指定它返回由FK链接的单个对象?
我的观点类:
class OrganisationDetail(mixins.RetrieveModelMixin, mixins.UpdateModelMixin,generics.GenericAPIView):
serializer_class = OrganisationDetailSerializer
lookup_field = 'pk' #yes, I know this is the default and there's no need to speciy
def get_queryset(self):
return Organisation.objects.filter(pk=self.request.user.organisation_id)
def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)
def put(self, request, *args, **kwargs):
return self.update(request, *args, …Run Code Online (Sandbox Code Playgroud) 我不明白为什么特定字段会在 valid_data 中被删除。
当将输入发布到 create() 一个新实例时,以下行:
thisLabel = ClassificationLabel.objects.get(identifier=label.identifier)
抛出错误,因为标识符属性不存在:
AttributeError at /api/v1/policies/
Run Code Online (Sandbox Code Playgroud)
'collections.OrderedDict' object has no attribute 'identifier
我在 Django REST 框架中有以下序列化器:
序列化器.py:
class ClassificationLabelDetailSerializer(serializers.ModelSerializer):
class Meta:
model = ClassificationLabel
fields = ('displayName', 'helpText', 'identifier', 'backgroundColour', 'foregroundColour', 'comment', 'description', 'lastChanged', 'revision')
read_only_fields = ('identifier', 'lastChanged', 'revision',)
class PolicySerializer(serializers.ModelSerializer):
labels = ClassificationLabelDetailSerializer(many=True)
class Meta:
model = Policy
fields = ('displayName', 'identifier', 'labels', 'lastChanged', 'description', 'comment')
read_only_fields = ('identifier', 'lastChanged',)
def create(self,validated_data):
labelData = validated_data.pop('labels')
thisPolicy = Policy.objects.create(**validated_data)
for label in …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用 Dexie,我似乎遇到了麻烦。
我有一个小型数据库(少于 1000 行),一旦我知道该行已发送到远程 API,我就会尝试逐行删除该行。我也可以成功保存到表(由一个 ID 和一个存储序列化对象的列定义)
这是我的代码:
if (online) {
//we query the db and send each event
database.open()
let allEvents = database.events.toCollection()
let total = allEvents.count(function (count) {
console.log(count + ' events in total')
//a simple test to ensure we're seeing the right number of records
})
allEvents.each(function(thisEvent){
//push to remote API
console.log('deleting ' + thisEvent.id)
database.events.delete(thisEvent.id) //<= this doesn't seem to be working
})
}
Run Code Online (Sandbox Code Playgroud)
除了最后的 delete 语句之外,所有这些都是如此。关于我应该如何解决这个问题的任何想法?对我来说重要的是逐行删除。
提前致谢!
我在这里看了很多线程(以及官方的例子),但我似乎找不到类似于我自己的问题.
我可能在这里有点厚 - 我的%QUERY字符串作为远程查询的一部分传递,我显然不想要.例:
"NetworkError: 404 NOT FOUND - http://local.example.co:8000/search-schools/%QUERY"`
Run Code Online (Sandbox Code Playgroud)
这是我的JS(你可以看到我在页面上有多个输入框,每个输入框都在一个单独的bootstrap3选项卡上(这将是另一个问题的焦点):
<script type="text/javascript">
var schoolSource = new Bloodhound({
hint: false,
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/search-schools/%QUERY'
}
});
schoolSource.initialize();
</script>
<script type="text/javascript">
$('#schoolSearch1').typeahead(null, {
name: 'schoolSearch1',
displayKey: 'name',
source: schoolSource
});
</script>
<script type="text/javascript">
$('#schoolSearch2').typeahead(null, {
name: 'schoolSearch2',
displayKey: 'name',
source: schoolSource
});
</script>
Run Code Online (Sandbox Code Playgroud)
行为: 我可以看到,当我在输入框中输入搜索文本时,会尝试与远程URL进行通信,但它会传递文字%QUERY字符串而不是输入框中的字符串.
我究竟做错了什么?如何将查询字符串传递给bloodhound?
我有一个似乎是一个基本的路径问题,但我无法弄清楚我的生活.
我有以下目录结构:
??? rockitt
??? activities
? ??? migrations
? ??? templates
? ? ??? activities
? ??? templatetags
??? blog
? ??? settings
Run Code Online (Sandbox Code Playgroud)
内blog/settings我有:
base.py dev.py __init.py__
__init.py__ 在上面的目录中包含:
from .dev import *
运行manage.py之类的东西时,我收到以下错误:
ImportError: Could not import settings 'blog.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named settings
到目前为止我尝试了什么:
我已经检查了manage.py运行时存在哪些路径,以下路径位于列表顶部:
rockitt
lib/python2.7/Django-1.7.7-py2.7.egg
lib/python2.7
[other dirs...]
ENV/lib/python27.zip
ENV/lib/python2.7
ENV/lib/python2.7/plat-linux2
ENV/lib/python2.7/lib-tk
ENV/lib/python2.7/lib-old
ENV/lib/python2.7/lib-dynload
/usr/local/lib/python2.7
/usr/local/lib/python2.7/plat-linux2
/usr/local/lib/python2.7/lib-tk
ENV/lib/python2.7/site-packages
我试图手动加载设置,没有运气文件:从博客/设置目录我已经尝试(我不知道这是否是测试这个但是基于阅读的正确方法此: …
我正在开发第一个模板上下文处理器。
它产生一个错误: Module "bookings.context_processors" does not define a "context_processors" attribute/class
我遵循了许多示例,但是这对我来说并没有太大意义。有人可以告诉我为什么会产生此错误吗?
代码很简单:
context_processors.py:
from bookings.models import Booking, BookingItem
def injectBookingObject(request):
try:
booking = request.session['bookingID']
bookingOptions = BookingItem.objects.all().filter(bookingID = booking)
return {
'bookingContents' : bookingOptions,
}
except:
return {}
Run Code Online (Sandbox Code Playgroud)
设置:
TEMPLATE_CONTEXT_PROCESSORS = (
*** usual ones *****
'bookings.context_processors'
)
Run Code Online (Sandbox Code Playgroud)
views.py:
def activity_detail(request, slug):
if request.method == 'GET':
selectedactivity = get_object_or_404(Activity, urlKey=slug)
activityMedia = ActivityMedia.objects.all().filter(
Activity = selectedactivity, MediaStatus = 1,
MediaActiveDate__lte=datetime.datetime.now(),
MediaInactiveDate__gte=datetime.datetime.now()
).exclude(MediaType = 'T').order_by('-MediaType', 'MediaSortOrder')
activityOptions = ActivityOption.objects.all().filter( …Run Code Online (Sandbox Code Playgroud)