Rename foreign key relationships on models from baby to child.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-16 10:29:53 -04:00
parent 35723b28c3
commit 6a88ff0ea7
2 changed files with 25 additions and 25 deletions

View File

@ -15,34 +15,34 @@ class ChildAdmin(admin.ModelAdmin):
@admin.register(DiaperChange) @admin.register(DiaperChange)
class DiaperChangeAdmin(admin.ModelAdmin): class DiaperChangeAdmin(admin.ModelAdmin):
list_display = ('baby', 'time', 'wet', 'solid', 'color') list_display = ('child', 'time', 'wet', 'solid', 'color')
list_filter = ('baby', 'wet', 'solid', 'color') list_filter = ('child', 'wet', 'solid', 'color')
search_fields = ('baby__first_name', 'baby__last_name',) search_fields = ('child__first_name', 'child__last_name',)
@admin.register(Feeding) @admin.register(Feeding)
class FeedingAdmin(admin.ModelAdmin): class FeedingAdmin(admin.ModelAdmin):
list_display = ('start', 'end', 'duration', 'baby', 'type', 'method',) list_display = ('start', 'end', 'duration', 'child', 'type', 'method',)
list_filter = ('baby', 'type', 'method',) list_filter = ('child', 'type', 'method',)
search_fields = ('baby__first_name', 'baby__last_name', 'type', 'method',) search_fields = ('child__first_name', 'child__last_name', 'type', 'method',)
@admin.register(Note) @admin.register(Note)
class NoteAdmin(admin.ModelAdmin): class NoteAdmin(admin.ModelAdmin):
list_display = ('time', 'baby', 'note',) list_display = ('time', 'child', 'note',)
list_filter = ('baby',) list_filter = ('child',)
search_fields = ('baby__last_name',) search_fields = ('child__last_name',)
@admin.register(Sleep) @admin.register(Sleep)
class SleepAdmin(admin.ModelAdmin): class SleepAdmin(admin.ModelAdmin):
list_display = ('start', 'end', 'duration', 'baby',) list_display = ('start', 'end', 'duration', 'child',)
list_filter = ('baby',) list_filter = ('child',)
search_fields = ('baby__first_name', 'baby__last_name',) search_fields = ('child__first_name', 'child__last_name',)
@admin.register(TummyTime) @admin.register(TummyTime)
class TummyTimeAdmin(admin.ModelAdmin): class TummyTimeAdmin(admin.ModelAdmin):
list_display = ('start', 'end', 'duration', 'baby', 'milestone',) list_display = ('start', 'end', 'duration', 'child', 'milestone',)
list_filter = ('baby',) list_filter = ('child',)
search_fields = ('baby__first_name', 'baby__last_name', 'milestone',) search_fields = ('child__first_name', 'child__last_name', 'milestone',)

View File

@ -23,7 +23,7 @@ class Child(models.Model):
class DiaperChange(models.Model): class DiaperChange(models.Model):
baby = models.ForeignKey('Child', related_name='diaper_change') child = models.ForeignKey('Child', related_name='diaper_change')
time = models.DateTimeField(blank=False, null=False) time = models.DateTimeField(blank=False, null=False)
wet = models.BooleanField() wet = models.BooleanField()
solid = models.BooleanField() solid = models.BooleanField()
@ -41,11 +41,11 @@ class DiaperChange(models.Model):
ordering = ['-time'] ordering = ['-time']
def __str__(self): def __str__(self):
return 'Diaper change for {} on {}'.format(self.baby, self.time.date()) return 'Diaper change for {} on {}'.format(self.child, self.time.date())
class Feeding(models.Model): class Feeding(models.Model):
baby = models.ForeignKey('Child', related_name='feeding') child = models.ForeignKey('Child', related_name='feeding')
start = models.DateTimeField(blank=False, null=False) start = models.DateTimeField(blank=False, null=False)
end = models.DateTimeField(blank=False, null=False) end = models.DateTimeField(blank=False, null=False)
type = models.CharField(max_length=255, choices=[ type = models.CharField(max_length=255, choices=[
@ -66,14 +66,14 @@ class Feeding(models.Model):
def __str__(self): def __str__(self):
return 'Feeding for {} on {} ({})'.format( return 'Feeding for {} on {} ({})'.format(
self.baby, self.end.date(), self.duration()) self.child, self.end.date(), self.duration())
def duration(self): def duration(self):
return duration_string(self.start, self.end) return duration_string(self.start, self.end)
class Note(models.Model): class Note(models.Model):
baby = models.ForeignKey('Child', related_name='note') child = models.ForeignKey('Child', related_name='note')
note = models.TextField() note = models.TextField()
time = models.DateTimeField(auto_now=True) time = models.DateTimeField(auto_now=True)
@ -84,11 +84,11 @@ class Note(models.Model):
ordering = ['-time'] ordering = ['-time']
def __str__(self): def __str__(self):
return 'Note about {} on {}'.format(self.baby, self.time.date()) return 'Note about {} on {}'.format(self.child, self.time.date())
class Sleep(models.Model): class Sleep(models.Model):
baby = models.ForeignKey('Child', related_name='sleep') child = models.ForeignKey('Child', related_name='sleep')
start = models.DateTimeField(blank=False, null=False) start = models.DateTimeField(blank=False, null=False)
end = models.DateTimeField(blank=False, null=False) end = models.DateTimeField(blank=False, null=False)
@ -101,14 +101,14 @@ class Sleep(models.Model):
def __str__(self): def __str__(self):
return 'Sleep for {} on {} ({})'.format( return 'Sleep for {} on {} ({})'.format(
self.baby, self.end.date(), self.duration()) self.child, self.end.date(), self.duration())
def duration(self): def duration(self):
return duration_string(self.start, self.end) return duration_string(self.start, self.end)
class TummyTime(models.Model): class TummyTime(models.Model):
baby = models.ForeignKey('Child', related_name='tummy_time') child = models.ForeignKey('Child', related_name='tummy_time')
start = models.DateTimeField(blank=False, null=False) start = models.DateTimeField(blank=False, null=False)
end = models.DateTimeField(blank=False, null=False) end = models.DateTimeField(blank=False, null=False)
milestone = models.CharField(max_length=255, blank=True) milestone = models.CharField(max_length=255, blank=True)
@ -121,7 +121,7 @@ class TummyTime(models.Model):
def __str__(self): def __str__(self):
return 'Tummy time for {} on {} ({})'.format( return 'Tummy time for {} on {} ({})'.format(
self.baby, self.end.date(), self.duration()) self.child, self.end.date(), self.duration())
def duration(self): def duration(self):
return duration_string(self.start, self.end) return duration_string(self.start, self.end)