数学和更改字段颜色
from django.db import models
from django.contrib.auth.models import User
class Product(models.Model):
name = models.CharField(max_length = 127)
description = models.TextField()
code = models.CharField(max_length = 30)
lot_no = models.CharField(max_length = 30)
inventory = models.IntegerField()
commited = models.IntegerField()
reorder = models.IntegerField()
created_date = models.DateField(auto_now_add = True)
comment_user = models.ForeignKey(User, null=True)
comment_txt = models.TextField()
def __unicode__(self):
return self.code + " - " + self.name + " - " + self.lot_no + " - " + str(self.created_date)
@property
def available(self):
return self.inventory - self.commited
admin.py
from django.contrib import admin
from CMS.Inventory.models import Product
class padmin(admin.ModelAdmin):
search_fields=['name', 'description', 'code', 'lot_no' ]
admin.site.register(Product, padmin)
我试图创建一个不可编辑但在 django 产品类中可见的字段,该类在 @property 字段中执行数学运算。我还尝试对可重新订购的产品进行比较,如果重新订购的数量少于可用的数量,则重新订购字段将变为红色,表明您需要订购更多。谢谢
from django.db import models
from django.contrib.auth.models import User
class Product(models.Model):
name = models.CharField(max_length = 127)
description = models.TextField()
code = models.CharField(max_length = 30)
lot_no = models.CharField(max_length = 30)
inventory = models.IntegerField()
commited = models.IntegerField()
reorder = models.IntegerField()
created_date = models.DateField(auto_now_add = True)
comment_user = models.ForeignKey(User, null=True)
comment_txt = models.TextField()
def __unicode__(self):
return self.code + " - " + self.name + " - " + self.lot_no + " - " + str(self.created_date)
@property
def available(self):
return self.inventory - self.commited
admin.py
from django.contrib import admin
from CMS.Inventory.models import Product
class padmin(admin.ModelAdmin):
search_fields=['name', 'description', 'code', 'lot_no' ]
admin.site.register(Product, padmin)
I am trying to make a field that is non editable but viewable in the django product class that does the math thats in the @property field. I am also trying to do a comparison of available to reorder such that if reorder is less than available the reorder field will become red showing that you needed to order more. Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将此信息发送给您的模型管理员 (padmin):
And this to your model admin (padmin):