我正在使用基本的android应用程序,我不知道在android studio中添加jar文件的位置.
我希望用户只能更新一个特定字段.例如:
class Snippet(models.Model):
created = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=100, blank=True, default='')
code = models.TextField()
linenos = models.BooleanField(default=False)
language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)
class Meta:
ordering = ('created',)
Run Code Online (Sandbox Code Playgroud)
class SnippetSerializer(serializers.ModelSerializer):
class Meta:
model = Snippet
fields = ('id', 'title', 'code', 'linenos', 'language', 'style')
Run Code Online (Sandbox Code Playgroud)
class SnippetList(generics.ListCreateAPIView):
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer
class SnippetDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer
Run Code Online (Sandbox Code Playgroud)
一旦Snippet创建,用户应该只能更新title字段.
我知道我可以通过以下方式实现这一目标:
def update(self, instance, validated_data):
"""
Update and …Run Code Online (Sandbox Code Playgroud) 我正在声明一个包含图像的界面.我需要给它什么类型.
export interface AdInterface {
email: string;
mobile: number;
image?: ??
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用factory_boy测试两个Django模型之间的多对多关系.factory_boy文档似乎没有讨论这个问题,我无法弄清楚我做错了什么.当我运行第一个测试时,我得到错误"AttributeError:'Pizza'对象没有属性'顶部'".第二次测试我得到了类似的错误.
当我在调试器中运行测试时,我可以看到"浇头"对象,但它不知道如何从中获取名称.我是否正确定义了PizzaFactory的_prepare方法?当你有多对多的关系时,如何从另一个表中访问一个表中的名称?
谢谢.
from django.db import models
class Topping(models.Model):
name = models.CharField(max_length=50)
def __unicode__(self):
return self.name
class Pizza(models.Model):
name = models.CharField(max_length=100)
toppings = models.ManyToManyField(Topping)
def __unicode__(self):
return self.name
Run Code Online (Sandbox Code Playgroud)
import factory
from models import Topping, Pizza
class ToppingFactory(factory.Factory):
name = 'mushrooms'
class PizzaFactory(factory.Factory):
name = 'Vegetarian'
@classmethod
def _prepare(cls, create, **kwargs):
topping = ToppingFactory()
pizza = super(PizzaFactory, cls)._prepare(create, **kwargs)
pizza.toppings.add(topping)
return pizza
Run Code Online (Sandbox Code Playgroud)
from django.test import TestCase
import factory
from app.models import Topping, Pizza
from app.factories import ToppingFactory, PizzaFactory …Run Code Online (Sandbox Code Playgroud) 我Docker Image在Openshift. 我没有使用 nginx 来设置 [secure_scheme_headers]:https : //github.com/benoitc/gunicorn/issues/1766。
gunicorn --chdir /src/app wsgi:application --bind 0.0.0.0:8000 --workers 4 --timeout 180 -k gevent
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base_async.py", line 66, in handle
six.reraise(*sys.exc_info())
File "/usr/local/lib/python3.7/site-packages/gunicorn/six.py", line 625, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base_async.py", line 49, in handle
req = six.next(parser)
File "/usr/local/lib/python3.7/site-packages/gunicorn/http/parser.py", line 41, in __next__
self.mesg = self.mesg_class(self.cfg, self.unreader, self.req_count)
File "/usr/local/lib/python3.7/site-packages/gunicorn/http/message.py", line 181, in __init__
super(Request, self).__init__(cfg, unreader)
File "/usr/local/lib/python3.7/site-packages/gunicorn/http/message.py", …Run Code Online (Sandbox Code Playgroud) {
"item_image": [
"The submitted data was not a file. Check the encoding type on the form."
],
"item_thumb": [
"The submitted data was not a file. Check the encoding type on the form."
]
}
Run Code Online (Sandbox Code Playgroud)
我发布的数据是
{
"item_name": "Lural",
"item_image": "/home/prashant/Desktop/suede.png",
"item_thumb": "/home/prashant/Desktop/suede.png",
"item_description": "sd",
"item_mass": 1,
"item_category": "Make Up",
"item_sub_category": "Sub-Feminine",
"item_est_price": "123.12",
"item_wst_price": "120.34"
}
Run Code Online (Sandbox Code Playgroud)
适用于媒体类型应用/ json
@api_view(['GET', 'POST'])
def product_list(request):
if request.method == 'POST':
serializer = ProductSerializer( data=request.data)
# data.encode("base64")
if serializer.is_valid():
serializer.save() …Run Code Online (Sandbox Code Playgroud) 我更新了django-dynamic-model存储库以支持Django 1.9.我收到了这个错误:
CommandError:
Conflicting migrations detected; multiple leaf nodes in the migration
graph: (0001_initial, 0002_auto__add_field_dynamicschemafield_extra in
dynamicmodel).
To fix them run 'python manage.py makemigrations --merge'
Run Code Online (Sandbox Code Playgroud)
运行后python manage.py makemigrations --merge,我又出现了一个错误:
File "/local/lib/python2.7/sitepackages/django/core/management/__init__.py",
line 353, in execute_from_command_line
utility.execute()
File "/local/lib/python2.7/sitepackages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File
"/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File
"/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File
"/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 97, in handle
return self.handle_merge(loader, conflicts)
File
"/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 216, in handle_merge …Run Code Online (Sandbox Code Playgroud) 如何使用django_autcomplete_light将自动填充添加到表单中的一个字段.我有一个基于模型的表单,我想在firstname字段中添加自动完成功能.
到目前为止我做了以下事情:
安装django_autocomplete_light
更改了INSTALLED_APPS:
INSTALLED_APPS = (
'autocomplete_light',
'django.contrib.admin',
...
Run Code Online (Sandbox Code Playgroud)
将它添加到urls.py,这是我的urls.py:
来自django.conf.urls的import include,来自django.contrib的url导入管理员
urlpatterns = [
url(r"^admin/", include(admin.site.urls)),
url(r"^app/", include("app.urls")),
url(r"^autocomplete/", include("autocomplete_light.urls")),
url(r"^.*$", include("app.urls")),
]
Run Code Online (Sandbox Code Playgroud)
创建了一个名为autocomplete_light_registry.py的文件,并添加了以下内容:
import autocomplete_light as al
from .models import *
al.register(Person,
search_fields = ["^firstname"],
attrs={
"placeholder":"First name",
"data-autocomplete-minimum-characters":1,
},
widget_attrs={
"data-widget-maximum-values":4,
"class":"modern-style",
},
)
Run Code Online (Sandbox Code Playgroud)
改变了我的PersonForm:
class PersonForm(forms.ModelForm)
Run Code Online (Sandbox Code Playgroud)
至:
class PersonForm(autocomplete_light.ModelForm)
class Meta:
model = Person
autocomplete_fields = ("firstname")
Run Code Online (Sandbox Code Playgroud)
我还将以下行添加到表单的html页面:
{% include 'autocomplete_light/static.html' %}
Run Code Online (Sandbox Code Playgroud)
我导入了所有必要的jquery文件
但是自动完成功能不会出现.我没有得到任何错误.我按照文档教程.
我正在使用python manage.py runserver运行该应用程序.
编辑:
我将urlpatterns更改为(首先制作了django-autocomplete-light url):
urlpatterns = [ …Run Code Online (Sandbox Code Playgroud) 我想从不同的文本或 json 或 csv 文件中读取数据。我应该遵循哪种方法?
我已经阅读了这些博客File read,read 2GB text file with small RAM for the different approach of file reading 。
* Reading a file in chunks
* Reading file chunks concurrently
* Reading the entire file into memory
* Splitting a long string into words
* Scanning word by word
Run Code Online (Sandbox Code Playgroud)
无法找到使用小 RAM 读取文件的最快方法。
我无法从 django-taggit 序列化标签。我遵循了here的说明,但它已经过时了。
这是我所做的:
class TagsSerializer(serializers.WritableField):
def from_native(self, data):
if type(data) is not list:
raise ParseError("expected a list of data")
return data
def to_native(self, obj):
if type(obj) is not list:
return [tag.name for tag in obj.all()]
return obj
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
'module' 对象没有属性 'WritableField
显然 WritableField 已被弃用。
我正在使用 django 1.8、DRF 3.2 和 django-taggit-0.17。
django ×6
python ×4
android ×1
autocomplete ×1
factory-boy ×1
file ×1
go ×1
gunicorn ×1
jquery ×1
typescript ×1
unit-testing ×1