From 3468c380086e1a36fcdbc6a6208e5af9ad311019 Mon Sep 17 00:00:00 2001 From: Chris Giacofei Date: Fri, 7 Jun 2024 11:27:41 -0400 Subject: [PATCH] Rename yeast batch to propogation. Refrences to yeast `batches` are now `propogations`. Hopefully less confusing now... Closes #6 --- yeast/admin.py | 20 +++++------ yeast/forms.py | 4 +-- ..._options_rename_batch_yeast_propogation.py | 22 ++++++++++++ .../0003_rename_batch_propogation.py | 18 ++++++++++ yeast/models.py | 36 ++++++++----------- yeast/templates/yeast/batch.html | 2 +- yeast/templates/yeast/home.html | 8 ++--- yeast/views.py | 14 ++++---- 8 files changed, 78 insertions(+), 46 deletions(-) create mode 100644 yeast/migrations/0002_alter_batch_options_rename_batch_yeast_propogation.py create mode 100644 yeast/migrations/0003_rename_batch_propogation.py diff --git a/yeast/admin.py b/yeast/admin.py index b47279f..46128d9 100644 --- a/yeast/admin.py +++ b/yeast/admin.py @@ -2,15 +2,15 @@ from django.contrib import admin from django.urls import reverse from django.utils.html import format_html from django.apps import apps -from yeast.models import Yeast, Strain, Manufacturer, Storage, Batch +from yeast.models import Yeast, Strain, Manufacturer, Storage, Propogation from yeast.forms import YeastModelForm import beer from config.extras import BREWFATHER_APP_ROOT -class BatchInline(admin.TabularInline): - model = Batch +class PropogationInline(admin.TabularInline): + model = Propogation extra = 0 class SampleInline(admin.TabularInline): @@ -23,11 +23,11 @@ class StrainInline(admin.TabularInline): class ParentInline(admin.TabularInline): verbose_name = 'Parent Samples' - model = Batch.parent.through + model = Propogation.parent.through @admin.register(Yeast) class YeastAdmin(admin.ModelAdmin): - list_display = [ 'batch', 'url', 'lot_number', 'age', 'storage', 'viability', 'generation_num', 'cellcount', 'pitched', 'date_pitched', 'pitched_batch'] + list_display = [ 'propogation', 'url', 'lot_number', 'age', 'storage', 'viability', 'generation_num', 'cellcount', 'pitched', 'date_pitched', 'pitched_batch'] list_editable = ['pitched', 'date_pitched', 'pitched_batch', 'lot_number'] def batch_url(self, obj): @@ -43,7 +43,7 @@ class YeastAdmin(admin.ModelAdmin): class StrainAdmin(admin.ModelAdmin): list_display = ['name', 'long_name', 'manufacturer', 'avilable_batches'] inlines = [ - BatchInline, + PropogationInline, ] list_editable = ['long_name', 'manufacturer'] @@ -58,7 +58,7 @@ class StrainAdmin(admin.ModelAdmin): urls.append('{}'.format(url, url_text)) return format_html(', '.join(urls)) - avilable_batches.short_description = 'Available Batches' + avilable_batches.short_description = 'Available Propogation' @admin.register(Storage) class StorageAdmin(admin.ModelAdmin): @@ -78,8 +78,8 @@ class ManufacturerAdmin(admin.ModelAdmin): if obj.website: return format_html("{url}", url=obj.website) -@admin.register(Batch) -class BatchAdmin(admin.ModelAdmin): +@admin.register(Propogation) +class PropogationAdmin(admin.ModelAdmin): list_display = ['strain', 'consumed', 'source', 'parent_samples', 'production_date', 'avilable_samples', 'used_samples'] form = YeastModelForm filter_horizontal = ['parent'] @@ -89,7 +89,7 @@ class BatchAdmin(admin.ModelAdmin): ] def save_related(self, request, form, formsets, change): - super(BatchAdmin, self).save_related(request, form, formsets, change) + super(PropogationAdmin, self).save_related(request, form, formsets, change) if form.instance.source_batch: relate_samples = [x for x in Yeast.objects.all() if x.pitched_batch==form.instance.source_batch] for sample in relate_samples: diff --git a/yeast/forms.py b/yeast/forms.py index a25ffa4..c1c6b20 100644 --- a/yeast/forms.py +++ b/yeast/forms.py @@ -1,7 +1,7 @@ from django import forms from django.urls import reverse from django.http import HttpResponse, HttpResponseRedirect -from .models import Yeast, Batch, Strain +from .models import Yeast, Propogation, Strain import logging logger = logging.getLogger('django') @@ -30,7 +30,7 @@ class BatchAddForm(forms.ModelForm): # create meta class class Meta: # specify model to be used - model = Batch + model = Propogation # specify fields to be used fields = [ diff --git a/yeast/migrations/0002_alter_batch_options_rename_batch_yeast_propogation.py b/yeast/migrations/0002_alter_batch_options_rename_batch_yeast_propogation.py new file mode 100644 index 0000000..8860c85 --- /dev/null +++ b/yeast/migrations/0002_alter_batch_options_rename_batch_yeast_propogation.py @@ -0,0 +1,22 @@ +# Generated by Django 5.0.6 on 2024-06-07 15:16 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('yeast', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='batch', + options={'verbose_name': 'Propagation', 'verbose_name_plural': 'Propagations'}, + ), + migrations.RenameField( + model_name='yeast', + old_name='batch', + new_name='propogation', + ), + ] diff --git a/yeast/migrations/0003_rename_batch_propogation.py b/yeast/migrations/0003_rename_batch_propogation.py new file mode 100644 index 0000000..627b22e --- /dev/null +++ b/yeast/migrations/0003_rename_batch_propogation.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.6 on 2024-06-07 15:21 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('beer', '0001_initial'), + ('yeast', '0002_alter_batch_options_rename_batch_yeast_propogation'), + ] + + operations = [ + migrations.RenameModel( + old_name='Batch', + new_name='Propogation', + ), + ] diff --git a/yeast/models.py b/yeast/models.py index 339f9b7..fbe400d 100644 --- a/yeast/models.py +++ b/yeast/models.py @@ -48,7 +48,7 @@ class Strain(CustomModel): @property def batches_available(self): - return [x for x in Batch.objects.all() if not x.consumed and x.strain==self] + return [x for x in Propogation.objects.all() if not x.consumed and x.strain==self] def __str__(self): # Return a string that represents the instance @@ -68,13 +68,14 @@ class Storage(CustomModel): return self.name -class Batch(CustomModel): +class Propogation(CustomModel): """ Stores a batch of :model:`yeast.Yeast` of a single :model:`yeast.Strain`. Can be a single purchased pack, or multiple vials to be frozen from a starter. """ + BATCH_TYPES = { 'ST': 'Store', 'PR': 'Propogated', @@ -89,7 +90,7 @@ class Batch(CustomModel): notes = models.TextField(max_length=500, blank=True, null=True) def save(self, *args, **kwargs): - super(Batch, self).save(*args, **kwargs) + super(Propogation, self).save(*args, **kwargs) if self.source_batch: relate_samples = [x for x in Yeast.objects.all() if x.pitched_batch==self.source_batch] for sample in relate_samples: @@ -97,19 +98,19 @@ class Batch(CustomModel): @property def age(self): - return int(average([x.age for x in Yeast.available.all() if x.batch == self])) + return int(average([x.age for x in Yeast.available.all() if x.propogation == self])) @property def max_viability(self): - return int(max([x.viability for x in Yeast.available.all() if x.batch == self]) * 100) + return int(max([x.viability for x in Yeast.available.all() if x.propogation == self]) * 100) @property def min_viability(self): - return int(min([x.viability for x in Yeast.available.all() if x.batch == self]) * 100) + return int(min([x.viability for x in Yeast.available.all() if x.propogation == self]) * 100) @property def generation(self): - return int(average([x.generation_num for x in Yeast.available.all() if x.batch == self])) + return int(average([x.generation_num for x in Yeast.available.all() if x.propogation == self])) @property def beer_name(self): @@ -132,11 +133,11 @@ class Batch(CustomModel): @property def remaining_samples(self): - return [x for x in Yeast.available.all() if x.batch==self] + return [x for x in Yeast.available.all() if x.propogation==self] @property def used_samples(self): - return [x for x in Yeast.objects.all() if x.batch==self and x.pitched] + return [x for x in Yeast.objects.all() if x.propogation==self and x.pitched] def __str__(self): # Return a string that represents the instance @@ -148,7 +149,7 @@ class Yeast(CustomModel): Store an individual sample of yeast. """ id = DateUUIDField(primary_key=True) - batch = models.ForeignKey(Batch, on_delete=models.CASCADE) + propogation = models.ForeignKey(Propogation, on_delete=models.CASCADE) generation_num = models.IntegerField(default=0) storage = models.ForeignKey(Storage, on_delete=models.CASCADE) cellcount = models.IntegerField(default=100) @@ -163,7 +164,7 @@ class Yeast(CustomModel): @property def name(self): - return '{} {}'.format(self.id, self.batch.strain.name) + return '{} {}'.format(self.id, self.propogation.strain.name) @property def age(self): @@ -174,7 +175,7 @@ class Yeast(CustomModel): else: end_date = timezone.now().date() - return abs((self.batch.production_date-end_date).days) + return abs((self.propogation.production_date-end_date).days) @property def viability(self): @@ -183,13 +184,4 @@ class Yeast(CustomModel): def __str__(self): # Return a string that represents the instance - return '{} {}'.format(self.id, self.batch.strain.name) - -# class BeerBatch(CustomModel): - # brewfather_id = models.CharField(max_length=50) - # brewfather_num = models.IntegerField(default=1) - # brewfather_name = models.CharField(max_length=500, default='name') - - # def __str__(self): - # # Return a string that represents the instance - # return 'BF #{num}: {name}'.format(name=self.brewfather_name, num=self.brewfather_num) + return '{} {}'.format(self.id, self.propogation.strain.name) diff --git a/yeast/templates/yeast/batch.html b/yeast/templates/yeast/batch.html index 5daa397..36cdb2b 100644 --- a/yeast/templates/yeast/batch.html +++ b/yeast/templates/yeast/batch.html @@ -49,7 +49,7 @@
- Print Selected Labels for this Batch + Print Selected Labels for this Propogation

diff --git a/yeast/templates/yeast/home.html b/yeast/templates/yeast/home.html index 9881622..3eecfa3 100644 --- a/yeast/templates/yeast/home.html +++ b/yeast/templates/yeast/home.html @@ -16,7 +16,7 @@ input, label {

-

Batches

+

Yeast Propogations

{% csrf_token %} @@ -37,7 +37,7 @@ input, label {
- + +
diff --git a/yeast/views.py b/yeast/views.py index d8b2f10..d30688f 100644 --- a/yeast/views.py +++ b/yeast/views.py @@ -6,7 +6,7 @@ from django.urls import reverse from django.http import JsonResponse from django.contrib.auth.decorators import login_required -from yeast.models import Yeast, Batch, Strain +from yeast.models import Yeast, Propogation, Strain from config.extras import AveryLabel from yeast.forms import BatchAddForm, StrainAddForm @@ -18,12 +18,12 @@ class YeastListView(ListView): model = Yeast class BatchListView(ListView): - model = Batch + model = Propogation def sample(request, yeast_id): sample = get_object_or_404(Yeast, pk=yeast_id) - sample_batch = get_object_or_404(Batch, pk=sample.batch_id) + sample_batch = get_object_or_404(Propogation, pk=sample.batch_id) return render(request, 'yeast/sample.html', {'sample': sample, 'batch':sample_batch}) # @login_required @@ -43,7 +43,7 @@ def get_batch(request): return redirect(re_url) def home(request): - return render(request, 'yeast/home.html',{'batches': Batch.objects.all, 'strains': Strain.objects.all}) + return render(request, 'yeast/home.html',{'batches': Propogation.objects.all, 'strains': Strain.objects.all}) def batch(request, batch_id): """ @@ -55,7 +55,7 @@ def batch(request, batch_id): ``Template`` :template:`yeast/batch.html` """ - batch = get_object_or_404(Batch, pk=batch_id) + batch = get_object_or_404(Propogation, pk=batch_id) return render(request, 'yeast/batch.html', {'batch': batch}) def batch_labels(request, batch_id): @@ -69,7 +69,7 @@ def batch_labels(request, batch_id): """ skip_count = request.POST.get("skip_count", "") samples = request.POST.getlist("samples", "") - batch = get_object_or_404(Batch, pk=batch_id) + batch = get_object_or_404(Propogation, pk=batch_id) to_print = list(filter(lambda d: str(d.id) in samples, batch.yeast_set.all())) # Create the HttpResponse object with the appropriate PDF headers. @@ -96,7 +96,7 @@ def batch_labels(request, batch_id): return response class addBatch(CreateView): - model = Batch + model = Propogation form_class = BatchAddForm def get_success_url(self):