All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Django app with Item model (games/books/films/other categories), CRUD views, and login-required access. Login page at /accounts/login/ uses custom dark-themed template consistent with the site design. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from django import forms
|
|
from .models import Item
|
|
|
|
|
|
class ItemForm(forms.ModelForm):
|
|
progress_percent = forms.FloatField(
|
|
min_value=0,
|
|
max_value=100,
|
|
initial=0,
|
|
widget=forms.NumberInput(attrs={
|
|
'type': 'range',
|
|
'min': '0',
|
|
'max': '100',
|
|
'step': '1',
|
|
}),
|
|
)
|
|
|
|
class Meta:
|
|
model = Item
|
|
fields = [
|
|
'category', 'name', 'progress_percent', 'favorite',
|
|
'hours_played', 'total_hours',
|
|
'pages_read', 'total_pages',
|
|
'watched', 'duration_minutes',
|
|
]
|
|
widgets = {
|
|
'hours_played': forms.NumberInput(attrs={'step': '0.5', 'min': '0'}),
|
|
'total_hours': forms.NumberInput(attrs={'step': '0.5', 'min': '0'}),
|
|
'pages_read': forms.NumberInput(attrs={'min': '0'}),
|
|
'total_pages': forms.NumberInput(attrs={'min': '0'}),
|
|
'duration_minutes': forms.NumberInput(attrs={'min': '0'}),
|
|
}
|
|
|
|
def clean(self):
|
|
cleaned_data = super().clean()
|
|
category = cleaned_data.get('category')
|
|
if category != Item.GAMES:
|
|
cleaned_data['hours_played'] = None
|
|
cleaned_data['total_hours'] = None
|
|
if category != Item.BOOKS:
|
|
cleaned_data['pages_read'] = None
|
|
cleaned_data['total_pages'] = None
|
|
if category != Item.FILMS:
|
|
cleaned_data['watched'] = None
|
|
cleaned_data['duration_minutes'] = None
|
|
return cleaned_data
|