Skip to content

Commit 9806c4c

Browse files
committed
new code example for django models
1 parent abfadc1 commit 9806c4c

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

content/pages/examples/django/django-db-models-model.markdown

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ ACCESS_CHOICES = (
134134
~~ can_add = models.BooleanField(_("can add"), default=True)
135135
~~ can_delete = models.BooleanField(_("can delete"), default=True)
136136
~~ can_change_advanced_settings = models.BooleanField(_("can change advanced settings"),
137-
default=False)
137+
default=False)
138138
~~ can_publish = models.BooleanField(_("can publish"), default=True)
139139
~~ can_change_permissions = models.BooleanField(_("can change permissions"),
140140
default=False,
@@ -548,3 +548,81 @@ from sorl.thumbnail.conf import settings
548548
def __str__(self):
549549
return self.key
550550
```
551+
552+
553+
## Example 6 from django-push-notifications
554+
[django-push-notifications](https://github.com/jazzband/django-push-notifications)
555+
is a [Django](/django.html) app for storing and interacting with
556+
push notification services such as
557+
[Google's Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/)
558+
and
559+
[Apple Notifications](https://developer.apple.com/notifications/).
560+
The django-push-notification project's source code is available
561+
open source under the
562+
[MIT license](https://github.com/jazzband/django-push-notifications/blob/master/LICENSE).
563+
564+
[**django-push-notifications / push_notifications / models.py**](https://github.com/jazzband/django-push-notifications/blob/master/push_notifications/models.py)
565+
566+
```python
567+
from __future__ import unicode_literals
568+
569+
~~from django.db import models
570+
from django.utils.encoding import python_2_unicode_compatible
571+
from django.utils.translation import ugettext_lazy as _
572+
573+
from .fields import HexIntegerField
574+
from .settings import PUSH_NOTIFICATIONS_SETTINGS as SETTINGS
575+
576+
577+
CLOUD_MESSAGE_TYPES = (
578+
("FCM", "Firebase Cloud Message"),
579+
("GCM", "Google Cloud Message"),
580+
)
581+
582+
BROWSER_TYPES = (
583+
("CHROME", "Chrome"),
584+
("FIREFOX", "Firefox"),
585+
("OPERA", "Opera"),
586+
)
587+
588+
589+
@python_2_unicode_compatible
590+
~~class Device(models.Model):
591+
name = models.CharField(max_length=255, verbose_name=_("Name"),
592+
blank=True, null=True)
593+
active = models.BooleanField(
594+
verbose_name=_("Is active"), default=True,
595+
help_text=_("Inactive devices will"
596+
" not be sent notifications")
597+
)
598+
user = models.ForeignKey(
599+
SETTINGS["USER_MODEL"], blank=True, null=True,
600+
on_delete=models.CASCADE
601+
)
602+
date_created = models.DateTimeField(
603+
verbose_name=_("Creation date"), auto_now_add=True,
604+
null=True
605+
)
606+
application_id = models.CharField(
607+
max_length=64, verbose_name=_("Application ID"),
608+
help_text=_(
609+
"Opaque application identity, "
610+
"should be filled in for multiple"
611+
" key/certificate access"
612+
),
613+
blank=True, null=True
614+
)
615+
616+
class Meta:
617+
abstract = True
618+
619+
def __str__(self):
620+
return (
621+
self.name or
622+
str(self.device_id or "") or
623+
"%s for %s" % (self.__class__.__name__,
624+
self.user or "unknown user")
625+
)
626+
627+
# code continues on from here without further examples
628+
```

theme/templates/table-of-contents.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ <h4 class="bp"><a href="https://training.talkpython.fm/courses/explore_entrepren
220220
<h4 class="bp"><a href="https://www.deploypython.com/full-stack-python.html">Full Stack Python Supporter's Edition</a></h4>
221221
<h4 class="bp"><a href="https://www.deploypython.com/deploying-flask-web-apps.html">Deploying Flask Web Apps</a></h4>
222222
<hr>
223-
<div class="sns desc">I recommend the following books and videos that were created by fellow Python developers I personally know and have used myself as learning resources.</div>
223+
<div class="sns desc">These books and videos were created by fellow
224+
Python developers. I have used each one myself and recommend
225+
them all if you are looking to buy high quality resources.</div>
224226
<h4 class="bp"><a href="https://testdriven.io/courses/microservices-with-docker-flask-and-react/?utm_source=fsp">Microservices with Docker, Flask, and React</a> by <a href="https://testdriven.io/authors/herman/">Michael Herman</a></h4>
225227
</div>
226228
</div>

0 commit comments

Comments
 (0)