Skip to content

Commit

Permalink
add common model so we can inherit timestamped model wherever we want…
Browse files Browse the repository at this point in the history
…, DRY
  • Loading branch information
Kenan7 committed Feb 6, 2021
1 parent a29a176 commit 4d1e9d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions my_awesome_project/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models


class TimeStampedModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)

class Meta:
abstract = True
6 changes: 3 additions & 3 deletions my_awesome_project/fileapp/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models import (
CASCADE,
CharField,
Expand All @@ -11,6 +9,8 @@
Model,
)

from my_awesome_project.common import TimeStampedModel

User = get_user_model()
# User = settings.AUTH_USER_MODEL

Expand All @@ -24,7 +24,7 @@ def last_messages(self):
return self.all().order_by("-id")[:10]


class FileModel(Model):
class FileModel(TimeStampedModel):
name = CharField(max_length=20)
description = CharField(
max_length=1000, default="default file description"
Expand Down
13 changes: 13 additions & 0 deletions my_awesome_project/fileapp/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.contrib.auth import get_user_model

from config import celery_app

from .models import FileModel

User = get_user_model()


@celery_app.task()
def get_users_count():
"""A pointless Celery task to demonstrate usage."""
return User.objects.count()

0 comments on commit 4d1e9d2

Please sign in to comment.