add units and info

This commit is contained in:
Jens Timmerman 2018-09-16 15:31:21 +02:00
parent 0fb0c3a1d0
commit f046acc94d
4 changed files with 99 additions and 3 deletions

View File

@ -10,9 +10,25 @@ class PantryItemInLine(admin.TabularInline):
class PantryItemInLineAdmin(admin.ModelAdmin):
list_filter = ['expiry_date']
list_display = (
'pantry_item',
'quantity',
'expiry_date',
'size',
'unit',
'info',
)
class PantryItemAdmin(admin.ModelAdmin):
inlines = [PantryItemInLine]
list_display = (
'name',
'category',
'min_quantity',
'unit',
'info',
)
admin.site.register(PantryItem, PantryItemAdmin)
admin.site.register(PantryItemLine, PantryItemInLineAdmin)

View File

@ -0,0 +1,28 @@
# Generated by Django 2.1.1 on 2018-09-16 12:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('inventory', '0008_auto_20180916_1205'),
]
operations = [
migrations.AlterField(
model_name='pantryitem',
name='unit',
field=models.CharField(blank=True, choices=[('L', 'Liter'), ('GR', 'Grams'), ('Bags', 'Bags'), ('Roll', 'Roll')], max_length=20, null=True),
),
migrations.AlterField(
model_name='pantryitemline',
name='expiry_date',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='pantryitemline',
name='unit',
field=models.CharField(blank=True, choices=[('L', 'Liter'), ('GR', 'Grams'), ('Bags', 'Bags'), ('Roll', 'Roll')], max_length=20, null=True),
),
]

View File

@ -0,0 +1,33 @@
# Generated by Django 2.1.1 on 2018-09-16 12:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('inventory', '0009_auto_20180916_1219'),
]
operations = [
migrations.AlterField(
model_name='pantryitem',
name='min_quantity',
field=models.DecimalField(decimal_places=3, default=1, max_digits=32),
),
migrations.AlterField(
model_name='pantryitem',
name='unit',
field=models.CharField(blank=True, choices=[('L', 'Liter'), ('GR', 'Grams'), ('Bags', 'Bags'), ('Roll', 'Roll'), ('Tube', 'Tube'), ('Bag', 'Bag')], max_length=20, null=True),
),
migrations.AlterField(
model_name='pantryitemline',
name='size',
field=models.DecimalField(decimal_places=3, default=1, max_digits=32),
),
migrations.AlterField(
model_name='pantryitemline',
name='unit',
field=models.CharField(blank=True, choices=[('L', 'Liter'), ('GR', 'Grams'), ('Bags', 'Bags'), ('Roll', 'Roll'), ('Tube', 'Tube'), ('Bag', 'Bag')], max_length=20, null=True),
),
]

View File

@ -11,13 +11,29 @@ CATEGORIES = (
('SW', 'SWEETS'),
('SN', 'SNACKS'),
('SP', 'SPICES'),
('DR', 'DRINKS'),
)
UNITS = (
('L', 'miliLiter'),
('GR', 'Grams'),
('Roll', 'Roll'),
('Tube', 'Tube'),
('Bag', 'Bag'),
('Bar', 'Bar'),
('Pack', 'Pack'),
)
#class ShoppingList(models.Model):
class PantryItem(models.Model):
name = models.CharField(max_length=200)
category = models.CharField(max_length=200, choices=CATEGORIES)
min_quantity = models.IntegerField(default=1)
min_quantity = models.IntegerField(default=1) #, decimal_places=3, max_digits=32)
unit = models.CharField(max_length=20, null=True, blank=True, choices=UNITS)
info = models.CharField(max_length=200, null=True, blank=True)
def __str__(self):
return self.name
@ -25,7 +41,10 @@ class PantryItem(models.Model):
class PantryItemLine(models.Model):
pantry_item = models.ForeignKey(PantryItem, on_delete=models.PROTECT, default='UN' )
quantity = models.IntegerField(default=1)
expiry_date = models.DateField()
expiry_date = models.DateField(null=True, blank=True)
size = models.IntegerField(default=1) #, decimal_places=3, max_digits=32)
unit = models.CharField(max_length=20, null=True, blank=True, choices=UNITS)
info = models.CharField(max_length=200, null=True, blank=True)
def __str__(self):
return self.pantry_item.name + ' ' + self.quantity
return self.pantry_item.name + ' ' + str(self.quantity)