Django—模型的空管理形式。

时间:2022-10-16 15:52:48

I have one model "Inventario" like this:

我有一个这样的模型"Inventario"

class Inventario(models.Model):
    producto = models.ForeignKey(Producto)
    cantidad = models.DecimalField(default=0, decimal_places=2, max_digits=10)
    ubicacion = models.ForeignKey(Ubicacion, null=True, blank=True, related_name='en_inventario')
    epc = models.CharField(max_length=25)
    serial = models.CharField(max_length=35)
    fecha = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
        return '%s (%s)' % (self.producto.item, self.epc)

and registered in the admin.py like this:

并在管理员注册。py是这样的:

from almacen.models import Inventario
admin.site.register(Inventario)

The List of Entries are shown in the Admin

条目列表显示在Admin中

Django—模型的空管理形式。

But inside the details of one of that entries, nothing appears Django—模型的空管理形式。

但在其中一个条目的细节中,什么也没有出现

Even if I try to save and continue, an error is thrown Django—模型的空管理形式。

即使我尝试保存并继续,也会抛出一个错误

What is happening? This error is affecting only this Model

发生了什么?这个错误只影响这个模型

1 个解决方案

#1


1  

You probably can't use the default admin.py. Turn on DEBUG and try something like this:

您可能不能使用默认的admin.py。打开DEBUG并尝试以下操作:

from django.contrib import admin
from almacen.models import Inventario

class InventarioAdmin(admin.ModelAdmin):
    readonly_fields = ['producto', 'fecha', 'ubicacion']

admin.site.register(Inventario, InventarioAdmin)

I suspect that something (the ForeignKey? the auto_now_add field?) isn't being well-handled by the default Admin. Try shrinking the number of fields available.

我怀疑有什么东西(外国人?auto_now_add字段?)没有得到默认管理员的良好处理。尝试减少可用字段的数量。

See also the ModelAdmin docs

请参见ModelAdmin文档

#1


1  

You probably can't use the default admin.py. Turn on DEBUG and try something like this:

您可能不能使用默认的admin.py。打开DEBUG并尝试以下操作:

from django.contrib import admin
from almacen.models import Inventario

class InventarioAdmin(admin.ModelAdmin):
    readonly_fields = ['producto', 'fecha', 'ubicacion']

admin.site.register(Inventario, InventarioAdmin)

I suspect that something (the ForeignKey? the auto_now_add field?) isn't being well-handled by the default Admin. Try shrinking the number of fields available.

我怀疑有什么东西(外国人?auto_now_add字段?)没有得到默认管理员的良好处理。尝试减少可用字段的数量。

See also the ModelAdmin docs

请参见ModelAdmin文档