Changes between Initial Version and Version 2 of Ticket #26953
- Timestamp:
- Jul 27, 2016, 1:52:33 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #26953
- Property Cc added
-
Ticket #26953 – Description
initial v2 1 1 The unthinkable happened! 2 {{{ 2 {{{ 3 3 Traceback (most recent call last): 4 4 File "manage.py", line 14, in <module> … … 30 30 My model and manager setup 31 31 32 {{{ 33 34 # encoding=utf-8 35 from __future__ import unicode_literals, print_function 36 32 {{{#!python 37 33 from django.db import models 38 34 from django.db.models.manager import BaseManager 39 35 from django.db.models.query import QuerySet 40 from django.utils.translation import ugettext_lazy as _41 from django.core.exceptions import ValidationError42 43 36 44 37 class ExpenseQuerySet(QuerySet): 45 46 def all(self): 47 return super(ExpenseQuerySet, self).all().filter(deleted=False) 48 49 def delete(self): 50 return self.update(deleted=True) 51 38 pass 52 39 53 40 class ExpenseManager(BaseManager.from_queryset(ExpenseQuerySet)): 54 41 pass 55 42 56 57 def validate_period(value):58 if value not in [x[0] for x in Expense.PERIODS]:59 raise ValidationError(_("Period not in choices."))60 61 62 43 class Expense(models.Model): 63 64 PERIODS = (65 ('monthly', _("Monthly")),66 ('quarterly', _("Quarterly")),67 ('yearly', _("Monthly"))68 )69 70 period = models.CharField(verbose_name=_("Period"), choices=PERIODS, max_length=10,71 validators=[validate_period])72 73 amount = models.FloatField(verbose_name=_("Amount"))74 description = models.CharField(max_length=255, verbose_name=_("Description"))75 valid_from = models.DateField(verbose_name=_("Valid from"), null=True)76 valid_to = models.DateField(verbose_name=_("Valid to"), null=True)77 78 deleted = models.BooleanField(default=False, verbose_name=_("Deleted"))79 80 44 objects = ExpenseManager() 81 82 def delete(self, **kwargs):83 Expense.objects.filter(pk=self.pk).update(deleted=True)84 85 class Meta:86 verbose_name = _("Expense")87 verbose_name_plural = _("Expenses")88 permissions = (89 ('list_expenses', _("Can list expenses")),90 )91 92 45 }}} 93 94