Passed
Push — master ( 69718c...20d9e6 )
by Swen
02:10
created

  A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
rs 10
ccs 12
cts 12
cp 1
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A ocalizedModel.__init__() 0 18 4
1 1
from django.db import models
2
3 1
from .fields import LocalizedField, LocalizedValue
4
5
6 1
class LocalizedModel(models.Model):
7
    """A model that contains localized fields."""
8
9 1
    class Meta:
10 1
        abstract = True
11
12 1
    def __init__(self, *args, **kwargs):
13
        """Initializes a new instance of :see:LocalizedModel.
14
15
        Here we set all the fields that are of :see:LocalizedField
16
        to an instance of :see:LocalizedValue in case they are none
17
        so that the user doesn't explicitely have to do so."""
18
19 1
        super(LocalizedModel, self).__init__(*args, **kwargs)
20
21 1
        for field in self._meta.get_fields():
22 1
            if not isinstance(field, LocalizedField):
23 1
                continue
24
25 1
            value = getattr(self, field.name, None)
26 1
            if not isinstance(value, LocalizedValue):
27 1
                value = LocalizedValue()
28
29
            setattr(self, field.name, value)
30