Add an amount field to the Feeding model.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-16 18:07:25 -04:00
parent 0c03e93a72
commit 79472dcdbe
6 changed files with 12 additions and 8 deletions

View File

@ -21,7 +21,8 @@ class DiaperChangeSerializer(serializers.HyperlinkedModelSerializer):
class FeedingSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Feeding
fields = ('baby', 'start', 'end', 'duration', 'type', 'method')
fields = ('baby', 'start', 'end', 'duration', 'type', 'method',
'amount')
class NoteSerializer(serializers.HyperlinkedModelSerializer):

View File

@ -33,7 +33,7 @@ class FeedingViewSet(viewsets.ModelViewSet):
serializer_class = FeedingSerializer
def get_queryset(self):
params = ['baby__last_name', 'type', 'method']
params = ['baby__last_name', 'type', 'method', 'amount']
return filter_by_params(self.request, Feeding, params)

View File

@ -22,9 +22,11 @@ class DiaperChangeAdmin(admin.ModelAdmin):
@admin.register(Feeding)
class FeedingAdmin(admin.ModelAdmin):
list_display = ('start', 'end', 'duration', 'child', 'type', 'method',)
list_display = ('start', 'end', 'duration', 'child', 'type', 'method',
'amount')
list_filter = ('child', 'type', 'method',)
search_fields = ('child__first_name', 'child__last_name', 'type', 'method',)
search_fields = ('child__first_name', 'child__last_name', 'type',
'method',)
@admin.register(Note)

View File

@ -35,7 +35,7 @@ class DiaperChangeForm(forms.ModelForm):
class FeedingForm(forms.ModelForm):
class Meta:
model = Feeding
fields = ['child', 'start', 'end', 'type', 'method']
fields = ['child', 'start', 'end', 'type', 'method', 'amount']
widgets = {
'start': forms.DateTimeInput(attrs={
'class': 'datepicker-input',

View File

@ -57,6 +57,7 @@ class Feeding(models.Model):
('left breast', 'Left breast'),
('right breast', 'Right breast'),
])
amount = models.FloatField(blank=True, null=True)
objects = models.Manager()

View File

@ -11,11 +11,11 @@
<tr>
<th>#</th>
<th>Child</th>
<th>Start</th>
<th>End</th>
<th>Date</th>
<th>Duration</th>
<th>Type</th>
<th>Method</th>
<th>Amount (oz)</th>
<th class="text-center">Actions</th>
</tr>
</thead>
@ -25,10 +25,10 @@
<th scope="row">{{ feeding.id }}</th>
<td>{{ feeding.child }}</td>
<td>{{ feeding.start }}</td>
<td>{{ feeding.end }}</td>
<td>{{ feeding.duration }}</td>
<td>{{ feeding.type }}</td>
<td>{{ feeding.method }}</td>
<td>{{ feeding.amount }}</td>
<td class="text-center">
<div class="btn-group btn-group-sm" role="group" aria-label="Actions">
<a href="{% url 'feeding-update' feeding.id %}" class="btn btn-primary"><i class="fa fa-pencil" aria-hidden="true"></i></a>