小编Kat*_*ine的帖子

Django 1.2.1许多字段的内联管理员

我最近升级到Django 1.2.1,因为我特别感兴趣的是能够拥有基本的多对多内联字段.当像这样使用管理员时:

初始模型:

class Ingredient(models.Model):
    name = models.TextField()

class Recipe(models.Model):
    ingredients = models.ManyToManyField(Ingredient)
Run Code Online (Sandbox Code Playgroud)

初始管理员:

class IngredientInline(admin.TabularInline):
      model = Recipe.ingredients.through

class RecipeOptions(admin.ModelAdmin):
    inlines = [IngredientInline,]
    exclude = ('ingredients',)

admin.site.register(Recipe,RecipeOptions)        
Run Code Online (Sandbox Code Playgroud)

我得到的是你在ManyToMany字段中通常看到的相同形式,还有一些额外的行.为它提供额外的参数,如Ingredient ModelForm没有帮助.通过model = Foo.manyfields.through怀疑基本的ModelForm关联可能有问题,我决定看看中间模型是否有帮助.它现在通过以下方式显示工作内联表单:

新款:

class RecipeJoin(models.Model):
    pass

class Recipe(models.Model):
    ingredients = models.ManyToManyField(RecipeJoin,through='Ingredient')

class Ingredient(models.Model):  
    name = models.TextField()
    test = models.ForeignKey(RecipeJoin,null=True,blank=True,editable=False)
Run Code Online (Sandbox Code Playgroud)

新管理员:

class IngredientInline(admin.TabularInline):
    model = Recipe.ingredients.through

class RecipeOptions(admin.ModelAdmin):
    inlines = [IngredientInline,]

admin.site.register(Recipe,RecipeOptions)
Run Code Online (Sandbox Code Playgroud)

显然这不是我想要使用的黑客.任何人都知道如何通过内联形式显示多种关系,而无需(a)创建一个全新的BasicInline表单和模板,或者(b)通过中间(或通用管理)模型放置它?

TIA.(我为冗长而道歉,这是我的第一篇文章,所以想要彻底).

django django-forms django-admin

12
推荐指数
1
解决办法
1万
查看次数

DataLab云部署403错误

我正在尝试部署DataLab.已确认我的项目位于美国区域.我尝试过创建新项目并在那里部署,但无济于事.到目前为止看来一切正常.重要的是要注意,我的项目ID没有前面的s~(不确定是否重要或者它只是DataLab/Google Cloud中使用的符号.我在两天内尝试了~10次但没有成功.

Nov  7 13:32:06 datalab-deploy-main-20151107-13-29-51 startupscript: Verifying that Managed VMs are enabled and ready.
Nov  7 13:32:06 datalab-deploy-main-20151107-13-29-51 startupscript: If this is your first deployment, this may take a while...#015If this is your first deployment, this may take a while...done.
Nov  7 13:32:06 datalab-deploy-main-20151107-13-29-51 startupscript: WARNING: If this is your first deployment, please try again.
Nov  7 13:32:06 datalab-deploy-main-20151107-13-29-51 startupscript: ERROR: (gcloud.preview.app.deploy) Server responded with code [403]:
Nov  7 13:32:06 datalab-deploy-main-20151107-13-29-51 startupscript:   Forbidden Unexpected HTTP status 403.
Nov  7 …
Run Code Online (Sandbox Code Playgroud)

google-cloud-platform google-cloud-datalab

2
推荐指数
1
解决办法
763
查看次数