diff --git a/sau/admin.py b/sau/admin.py index 0ff4413..189a232 100644 --- a/sau/admin.py +++ b/sau/admin.py @@ -18,7 +18,7 @@ def get_queryset(self, request): return qs.filter(farmers__in=[request.user]) -class SheepForm(FarmAwareModelAdmin): +class SheepFormAdmin(FarmAwareModelAdmin): """Sheep form, for overriding various fields in admin panel. Today we override: @@ -37,7 +37,7 @@ def __sheep_parent_filter(self, db_field, request, **kwargs): raise RuntimeError( 'Filter called on wrong field: %s' % str(db_field.name)) kwargs['queryset'] = Sheep.objects.filter(**filters) - return super(SheepForm, self).formfield_for_foreignkey( + return super().formfield_for_foreignkey( db_field, request, **kwargs) # To get user-aware dropdown list for farm of a sheep @@ -48,7 +48,7 @@ def __farm_filter(self, db_field, request, **kwargs): if not request.user.is_superuser: filters['farmers__in'] = [request.user] kwargs['queryset'] = Farm.objects.filter(**filters) - return super(SheepForm, self).formfield_for_foreignkey( + return super().formfield_for_foreignkey( db_field, request, **kwargs) # this is the method we're overriding, but only on fields @@ -59,11 +59,11 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs): return self.__sheep_parent_filter(db_field, request, **kwargs) if db_field.name == 'farm': return self.__farm_filter(db_field, request, **kwargs) - return super(SheepForm, self).formfield_for_foreignkey( + return super().formfield_for_foreignkey( db_field, request, **kwargs) -admin.site.register(Sheep, SheepForm) +admin.site.register(Sheep, SheepFormAdmin) admin.site.register(Medicine) admin.site.register(Dose) admin.site.register(Farm, FarmAwareModelAdmin) diff --git a/sau/forms.py b/sau/forms.py index 5a447c2..e9aeb97 100644 --- a/sau/forms.py +++ b/sau/forms.py @@ -30,3 +30,18 @@ def __init__(self, *args, **kwargs): self.fields['father'].queryset = Sheep.objects.filter(sex='m') # male self.fields['mother'].queryset = Sheep.objects.filter(sex='f') # female self.fields['birth_date_utc'].required = True + + +class SheepBatchForm(forms.Form): + rams = forms.IntegerField() + ewes = forms.IntegerField() + birth_date_utc = forms.CharField() + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + #self.fields['father'].queryset = Sheep.objects.filter(sex='m') # male + #self.fields['mother'].queryset = Sheep.objects.filter(sex='f') # female + + + def save(self, commit=True): + return super().save(commit=commit) diff --git a/sau/templates/index.html b/sau/templates/index.html index 46e132f..ddbf283 100644 --- a/sau/templates/index.html +++ b/sau/templates/index.html @@ -52,7 +52,9 @@