Coverage for src/expo_notifications/models/device.py: 100%

1 from django.conf import settings

2 from django.db import models

3 from django.utils import timezone

4

5 from expo_notifications.managers import DeviceManager

6

7

8 class Device(models.Model):

9 objects = DeviceManager()

10

11 user = models.ForeignKey(

12 to=settings.AUTH_USER_MODEL,

13 on_delete=models.CASCADE,

14 related_name="devices",

15 )

16

17 lang = models.CharField(

18 # e.g. for ISO 639-1 & ISO 3166-1 alpha-2

19 max_length=5,

20 blank=True,

21 )

22

23 push_token = models.CharField(

24 # https://github.com/expo/expo/issues/1135#issuecomment-399622890

25 max_length=4096,

26 )

27

28 date_registered = models.DateTimeField(

29 default=timezone.now,

30 )

31

32 is_active = models.BooleanField(

33 default=True,

34 )

35

36 class Meta:

37 unique_together = (

38 "user",

39 "push_token",

40 )

41

42 def __str__(self) -> str:

43 return f"Device #{self.pk} of {self.user.username}"