[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin updates #2823

Merged
merged 5 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 40 additions & 13 deletions cookbook/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class UserSpaceAdmin(admin.ModelAdmin):


class UserPreferenceAdmin(admin.ModelAdmin):
list_display = ('name', 'theme', 'nav_color', 'default_page',)
list_display = ('name', 'theme', 'nav_color', 'default_page')
search_fields = ('user__username',)
list_filter = ('theme', 'nav_color', 'default_page',)
date_hierarchy = 'created_at'
Expand All @@ -75,7 +75,7 @@ def name(obj):


class SearchPreferenceAdmin(admin.ModelAdmin):
list_display = ('name', 'search', 'trigram_threshold',)
list_display = ('name', 'search', 'trigram_threshold', )
search_fields = ('user__username',)
list_filter = ('search',)

Expand Down Expand Up @@ -108,11 +108,16 @@ class SupermarketCategoryInline(admin.TabularInline):


class SupermarketAdmin(admin.ModelAdmin):
list_display = ('name', 'space',)
inlines = (SupermarketCategoryInline,)


class SupermarketCategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'space',)


admin.site.register(Supermarket, SupermarketAdmin)
admin.site.register(SupermarketCategory)
admin.site.register(SupermarketCategory, SupermarketCategoryAdmin)


class SyncLogAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -163,10 +168,18 @@ def delete_unattached_steps(modeladmin, request, queryset):


class StepAdmin(admin.ModelAdmin):
list_display = ('name', 'order',)
search_fields = ('name',)
list_display = ('recipe_and_name', 'order', 'space')
ordering = ('recipe__name', 'name', 'space', )
search_fields = ('name', 'recipe__name')
actions = [delete_unattached_steps]
vabene1111 marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
@admin.display(description="Name")
def recipe_and_name(obj):
if not obj.recipe_set.exists():
return f"Orphaned Step{'':s if not obj.name else f': {obj.name}'}"
return f"{obj.recipe_set.first().name}: {obj.name}" if obj.name else obj.recipe_set.first().name


admin.site.register(Step, StepAdmin)

Expand All @@ -183,8 +196,9 @@ def rebuild_index(modeladmin, request, queryset):


class RecipeAdmin(admin.ModelAdmin):
list_display = ('name', 'internal', 'created_by', 'storage')
list_display = ('name', 'internal', 'created_by', 'storage', 'space')
search_fields = ('name', 'created_by__username')
ordering = ('name', 'created_by__username', )
list_filter = ('internal',)
date_hierarchy = 'created_at'

Expand All @@ -198,7 +212,14 @@ def created_by(obj):

admin.site.register(Recipe, RecipeAdmin)

admin.site.register(Unit)

class UnitAdmin(admin.ModelAdmin):
list_display = ('name', 'space')
ordering = ('name', 'space', )
search_fields = ('name',)


admin.site.register(Unit, UnitAdmin)


# admin.site.register(FoodInheritField)
Expand Down Expand Up @@ -229,10 +250,16 @@ def delete_unattached_ingredients(modeladmin, request, queryset):


class IngredientAdmin(admin.ModelAdmin):
list_display = ('food', 'amount', 'unit')
search_fields = ('food__name', 'unit__name')
list_display = ('recipe_name', 'amount', 'unit', 'food', 'space')
search_fields = ('food__name', 'unit__name', 'step__recipe__name')
actions = [delete_unattached_ingredients]

@staticmethod
@admin.display(description="Recipe")
def recipe_name(obj):
recipes = obj.step_set.first().recipe_set.all() if obj.step_set.exists() else None
return recipes.first().name if recipes else 'Orphaned Ingredient'


admin.site.register(Ingredient, IngredientAdmin)

Expand All @@ -258,7 +285,7 @@ class RecipeImportAdmin(admin.ModelAdmin):


class RecipeBookAdmin(admin.ModelAdmin):
list_display = ('name', 'user_name')
list_display = ('name', 'user_name', 'space')
search_fields = ('name', 'created_by__username')

@staticmethod
Expand Down Expand Up @@ -334,11 +361,11 @@ class ShoppingListEntryAdmin(admin.ModelAdmin):
admin.site.register(ShoppingListEntry, ShoppingListEntryAdmin)


class ShoppingListAdmin(admin.ModelAdmin):
list_display = ('id', 'created_by', 'created_at')
# class ShoppingListAdmin(admin.ModelAdmin):
# list_display = ('id', 'created_by', 'created_at')


admin.site.register(ShoppingList, ShoppingListAdmin)
# admin.site.register(ShoppingList, ShoppingListAdmin)


class ShareLinkAdmin(admin.ModelAdmin):
Expand Down
7 changes: 6 additions & 1 deletion cookbook/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,9 @@ class Ingredient(ExportModelOperationsMixin('ingredient'), models.Model, Permiss
space = models.ForeignKey(Space, on_delete=models.CASCADE)
objects = ScopedManager(space='space')

def __str__(self):
return f'{self.pk}: {self.amount} {self.food.name} {self.unit.name}'

class Meta:
ordering = ['order', 'pk']
indexes = (
Expand Down Expand Up @@ -745,7 +748,9 @@ def get_instruction_render(self):
return render_instructions(self)

def __str__(self):
return f'{self.pk} {self.name}'
if not self.recipe_set.exists():
return f"{self.pk}: {_('Orphaned Step')}"
return f"{self.pk}: {self.name}" if self.name else f"Step: {self.pk}"

class Meta:
ordering = ['order', 'pk']
Expand Down
Loading