views:

46

answers:

0
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