added comment field and a recipe filter to cook log
This commit is contained in:
parent
ae70064c06
commit
59ecc40dc6
@ -0,0 +1,33 @@
|
||||
# Generated by Django 4.2.7 on 2024-02-24 12:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0213_remove_property_property_unique_import_food_per_space_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='cooklog',
|
||||
name='comment',
|
||||
field=models.TextField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='cooklog',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='cooklog',
|
||||
name='rating',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='cooklog',
|
||||
name='servings',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
]
|
@ -1293,10 +1293,13 @@ class TelegramBot(models.Model, PermissionModelMixin):
|
||||
|
||||
class CookLog(ExportModelOperationsMixin('cook_log'), models.Model, PermissionModelMixin):
|
||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||
rating = models.IntegerField(null=True, blank=True)
|
||||
servings = models.IntegerField(null=True, blank=True)
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
|
||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(default=timezone.now)
|
||||
rating = models.IntegerField(null=True)
|
||||
servings = models.IntegerField(default=0)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
space = models.ForeignKey(Space, on_delete=models.CASCADE)
|
||||
objects = ScopedManager(space='space')
|
||||
|
@ -1200,6 +1200,8 @@ class ShareLinkSerializer(SpacedModelSerializer):
|
||||
|
||||
|
||||
class CookLogSerializer(serializers.ModelSerializer):
|
||||
created_by = UserSerializer(read_only=True)
|
||||
|
||||
def create(self, validated_data):
|
||||
validated_data['created_by'] = self.context['request'].user
|
||||
validated_data['space'] = self.context['request'].space
|
||||
@ -1207,7 +1209,7 @@ class CookLogSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = CookLog
|
||||
fields = ('id', 'recipe', 'servings', 'rating', 'created_by', 'created_at')
|
||||
fields = ('id', 'recipe', 'servings', 'rating', 'comment', 'created_by', 'created_at', 'updated_at')
|
||||
read_only_fields = ('id', 'created_by')
|
||||
|
||||
|
||||
|
@ -1270,8 +1270,13 @@ class CookLogViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = CookLogSerializer
|
||||
permission_classes = [CustomIsOwner & CustomTokenHasReadWriteScope]
|
||||
pagination_class = DefaultPagination
|
||||
query_params = [
|
||||
QueryParam(name='recipe', description=_('Filter for entries with the given recipe'), qtype='integer'),
|
||||
]
|
||||
|
||||
def get_queryset(self):
|
||||
if self.request.query_params.get('recipe', None):
|
||||
self.queryset = self.queryset.filter(recipe=self.request.query_params.get('recipe'))
|
||||
return self.queryset.filter(space=self.request.space)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user