我有自定义存储空间
import os
from django.core.files.storage import Storage
class AlwaysOverwriteFileSystemStorage(Storage):
def get_available_name(self, name):
"""
Directly Returns a filename that's
from what user input.
"""
if self.exists(name):
# Remove the existing file
os.remove(name)
# Return the input name as output
return name
Run Code Online (Sandbox Code Playgroud)
我想知道我应该在哪里放置他的AlwaysOverwriteFileSystemStorage.py文件以及settings.py如何定义DEFAULT_FILE_STORAGE
我的Django根文件夹是/ home/username/webapp
当我放DEFAULT_FILE_STORAGE = 'site.storage.AlwaysOverwriteFileSystemStorage',它返回一个
错误
导入存储模块site.storage时出错:"没有名为storage的模块"
我不熟悉Python/Django,任何帮助将不胜感激.谢谢.
我已经覆盖了list_display来显示这样的内联字段:
class opportunityAdmin(admin.ModelAdmin):
list_display = ('name', 'Contact', 'Phone', 'Address', 'discovery_date', 'status' , 'outcome')
search_fields = ['name', 'tags' , 'description']
#readonly_fields = ('discovery_date','close_date')
inlines = [account_contactInline, account_updateInline]
def Contact(self, obj):
return '<br/>'.join(c.account_poc for c in account_contact.objects.filter(opportunity=obj.id).order_by('id')[:1])
def Phone(self, obj):
return '<br/>'.join(c.account_phone for c in account_contact.objects.filter(opportunity=obj.id).order_by('id')[:1])
def Address(self, obj):
return '<br/>'.join(c.account_address for c in account_contact.objects.filter(opportunity=obj.id).order_by('id')[:1])
Run Code Online (Sandbox Code Playgroud)
我的问题是,在Django admin中,内联字段标题的显示名称分别使用了函数名称:Contact,Phone和Address.实际上我想用自定义文本显示那些字段标题.我甚至想用中文来展示它们.我错过了什么?
我有一个标准的Django Admin页面,用于上传多个文件.我希望做到以下几点:
我现在只有一个非常基本的管理页面.任何人都可以指出我从哪里开始的正确方向?请指出我需要修改哪个文件,因为我仍然不熟悉django.
只是一个简短的方向将不胜感激.谢谢.
从grappelli定制文档中,它建议:
The sortable-field will not automatically be hidden
(use a Hidden Input Widget if needed).
Run Code Online (Sandbox Code Playgroud)
但是,我已经搜索了这么久,并且不知道什么是"隐藏输入小部件"以及如何将其实现为Django模型.这是我的代码:
# models.py
class video(models.Model):
category = models.ForeignKey(subCategory)
index = PositionField('index')
video_title = models.CharField(max_length=255, blank=True, null=True)
video_desc = models.TextField(blank=True, null=True)
main_img = S3EnabledImageField(upload_to='video_img', blank=True, null=True)
small_img = S3EnabledImageField(upload_to='video_img', blank=True, null=True)
mid_img = S3EnabledImageField(upload_to='video_img', blank=True, null=True)
large_img = S3EnabledImageField(upload_to='video_img', blank=True, null=True)
last_updated = models.DateField(auto_now=True)
date_added = models.DateField()
date_modified = models.DateField()
date_published = models.DateField(blank=True, null=True)
date_closed = models.DateField(blank=True, null=True)
status = models.CharField(max_length=7,choices=STATUS_CHOICE)
class Meta:
ordering = ('index',) …Run Code Online (Sandbox Code Playgroud) 我是Django的新手.
我希望我的模型名称以中文显示,所以我在我的模型的元类中使用了verbose_name,代码如下:
#this models.py file is encoded in unicode
class TS_zone(models.Model):
index = models.IntegerField()
zone_name = models.CharField(max_length=50);
zone_icon = models.ImageField(upload_to='zone_icon', null=True)
is_active = models.NullBooleanField(blank=True, null=True)
status = models.CharField(max_length=7,choices=SETTING_STATUS_CHOICES)
class Meta:
ordering = ('index',)
verbose_name = u'????'
verbose_name_plural = u'??????'
def __unicode__(self):
return self.zone_name
Run Code Online (Sandbox Code Playgroud)
但是当我运行manage.py syncdb时,会抛出以下错误:
File "E:\pythonroot\myproject\..\myproject\myapp\models.py", line 19
SyntaxError: Non-ASCII character '\xe4' in file
E:\pythonroot\myproject\..\myproject\myapp\models.py on line 19, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
Run Code Online (Sandbox Code Playgroud)
似乎manage.py无法处理我的verbose_name中的非ascii字符.我做错了什么?
谢谢.
我有一个int currentFontSize,我想与存储在C数组中的NSString进行比较,这里是代码.
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
static NSString* fontSizeName[] =
{
@"14",
@"18",
@"22",
@"26",
@"30",
@"34",
};
int fontSizeSegmentID;
int currentFontSize = 22;
NSString *val = [NSString stringWithFormat: @"%i", currentFontSize];
NSString *val2 = @"22";
NSLog(@"the current font size is %i", currentFontSize);
NSLog(@"the current font Value1 is %i", val);
NSLog(@"the current font Value2 is %i",val2);
int i;
for (i = 0; i < 6; i++) {
NSLog(@"fontSizeNAme:%d",fontSizeName[i]);
NSLog(@"val:%d",val); …Run Code Online (Sandbox Code Playgroud) django ×5
python ×3
django-admin ×2
file-upload ×1
manage.py ×1
nsstring ×1
objective-c ×1
syncdb ×1