質問編集履歴

1

models.py追加

2021/06/12 09:04

投稿

masa530
masa530

スコア5

test CHANGED
File without changes
test CHANGED
@@ -136,7 +136,47 @@
136
136
 
137
137
  ```
138
138
 
139
+ ```
139
140
 
141
+ #models.py
142
+
143
+
144
+
145
+ from django.db import models
146
+
147
+ from django.contrib.auth.models import User
148
+
149
+ from django.core.validators import MaxValueValidator, MinValueValidator
150
+
151
+ # Create your models here.
152
+
153
+ class Food(models.Model):
154
+
155
+ user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
156
+
157
+ name = models.CharField(max_length=200)
158
+
159
+ kcal = models.PositiveSmallIntegerField()
160
+
161
+ protein = models.DecimalField(max_digits=4, decimal_places=1, blank=True, null=True, default=0.0, validators=[MaxValueValidator(999.9), MinValueValidator(0.0)])
162
+
163
+ fat = models.DecimalField(max_digits=4, decimal_places=1, blank=True, null=True, default=0.0, validators=[MaxValueValidator(999.9), MinValueValidator(0.0)])
164
+
165
+ carb = models.DecimalField(max_digits=4, decimal_places=1, blank=True, null=True, default=0.0, validators=[MaxValueValidator(999.9), MinValueValidator(0.0)])
166
+
167
+ description = models.TextField(null=True, blank=True)
168
+
169
+ eaten_date = models.DateField(editable=True, blank=True, null=True)
170
+
171
+ created = models.DateTimeField(auto_now_add=True)
172
+
173
+
174
+
175
+ def __str__(self):
176
+
177
+ return self.name
178
+
179
+ ```
140
180
 
141
181
  ### 試したこと
142
182