新类不与面板管理员django同步

时间:2015-07-17 11:07:47

标签: python django django-models django-admin-filters

我刚刚为我的项目定义了新类。当我运行服务器时,我不会发现错误,只是不会出现在admin-django Panel上。

以下是来自models.py

的新课程
class Stock_Clinicas(models.Model):
    organization = models.ForeignKey(Organization, null=True, blank=True, on_delete=models.SET_NULL)
    products = models.ForeignKey(Products, null=True, blank=True, on_delete=models.SET_NULL)
    provider = models.ForeignKey(Provider, null=True, blank=True, on_delete=models.SET_NULL)
    stock_min = models.DecimalField('Stock minimo', max_digits=10, decimal_places=0)
    stock_opt = models.DecimalField('Stock optimo', max_digits=10, decimal_places=0)
    stock_act = models.DecimalField('Stock actual', max_digits=10, decimal_places=0, default=0)

和我的admin.py。我会把所有代码都放好。

from django.contrib import admin
from stock.models import *

from .models import Organization, OrganizationUser, OrganizationOwner


class OwnerInline(admin.StackedInline):
    model = OrganizationOwner
    raw_id_fields = ('organization_user',)


class OrganizationAdmin(admin.ModelAdmin):
    inlines = [OwnerInline]
    list_display = ['name', 'is_active']
    prepopulated_fields = {"slug": ("name",)}


class OrganizationUserAdmin(admin.ModelAdmin):
    list_display = ['user', 'organization', 'is_admin']
    raw_id_fields = ('user', 'organization')


class OrganizationOwnerAdmin(admin.ModelAdmin):
    raw_id_fields = ('organization_user', 'organization')


class Stock_ClinicasAdmin(admin.ModelAdmin):
    list_display = ('stock_min', 'stock_opt', 'stock_act')


admin.site.register(Stock_Clinicas, Stock_ClinicasAdmin)
admin.site.register(Organization, OrganizationAdmin)
admin.site.register(OrganizationUser, OrganizationUserAdmin)
admin.site.register(OrganizationOwner, OrganizationOwnerAdmin)

忘了说,当我使用syncdb时,表格没有被创建。我正在使用Django 1.5。

尚未解决

2 个答案:

答案 0 :(得分:0)

在admin.py中,将modelAdmin类重命名为Stock_ClinicasAdmin(或您的模型名称的任何其他内容),并在modelAdmin类声明后添加:

admin.register(Stoc_Clinicas, Stock_ClinicasAdmin)

答案 1 :(得分:0)

你有几个问题:

class Stock_ClinicasAdmin(admin.ModelAdmin):
    list_display = ('Stock Minimo', 'Stock Actual', 'Stock Optimo')

您没有任何名为Stock Minimo的字段,字段为stock_min,因此您需要对其进行调整。

如果您刚刚创建了此应用,请确保:

  1. 您将其添加到INSTALLED_APPS;它应该有stock,
  2. 您可能希望运行manage.py makemigrationsmanage.py migrate来创建表格。