Skip to content

Fix issue #173: Add timestamps to models #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
39892f5
Fix issue #173: Add timestamps to models
openhands-agent Jan 24, 2025
1204c92
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 24, 2025
53ca2e5
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 24, 2025
ed78d34
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 24, 2025
6cbe74e
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 24, 2025
2883775
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
b6e9764
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
64a819b
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
ef30273
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
d82cff0
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
dac3022
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
21abca5
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
051a1be
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
c501e4b
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
989be89
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
3d182e2
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
d8b128f
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
aebe5db
Fix pr #174: Fix issue #173: Add timestamps to models
openhands-agent Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Generated by Django 4.2.8 on 2025-01-24 17:02

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("photo", "0004_alter_contest_prize"),
]

operations = [
migrations.AddField(
model_name="collection",
name="created_at",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AddField(
model_name="collection",
name="updated_at",
field=models.DateTimeField(auto_now=True, null=True),
),
migrations.AddField(
model_name="contest",
name="created_at",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AddField(
model_name="contest",
name="updated_at",
field=models.DateTimeField(auto_now=True, null=True),
),
migrations.AddField(
model_name="contestsubmission",
name="created_at",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AddField(
model_name="contestsubmission",
name="updated_at",
field=models.DateTimeField(auto_now=True, null=True),
),
migrations.AddField(
model_name="picture",
name="created_at",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AddField(
model_name="picture",
name="updated_at",
field=models.DateTimeField(auto_now=True, null=True),
),
migrations.AddField(
model_name="picturecomment",
name="updated_at",
field=models.DateTimeField(auto_now=True, null=True),
),
migrations.AddField(
model_name="user",
name="created_at",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AddField(
model_name="user",
name="updated_at",
field=models.DateTimeField(auto_now=True, null=True),
),
]
2 changes: 2 additions & 0 deletions photo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def create_superuser(self, email, password=None, **kwargs):


class SoftDeleteModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True, null=True)
updated_at = models.DateTimeField(auto_now=True, null=True)
is_deleted = models.BooleanField(default=False)
objects = SoftDeleteManager()
all_objects = models.Manager()
Expand Down
3 changes: 3 additions & 0 deletions photo/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Meta:
name_last = factory.Faker("last_name")
username = factory.Sequence(lambda n: "user{0}".format(n))
password = factory.Sequence(lambda n: "user{0}password".format(n))
created_at = factory.Faker("date_time", tzinfo=pytz.UTC)
updated_at = factory.Faker("date_time", tzinfo=pytz.UTC)
profile_picture_updated_at = timezone.now()

@factory.post_generation
Expand Down Expand Up @@ -147,6 +149,7 @@ class Meta:
model = ContestSubmission
skip_postgeneration_save = True

django_get_or_create = ('contest', 'picture')
contest = factory.SubFactory(ContestFactory)
picture = factory.SubFactory(
PictureFactory, user=factory.SubFactory(UserFactory, user_profile_picture=True)
Expand Down
11 changes: 11 additions & 0 deletions photo/tests/test_database/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ def test_factory_null(self):
def test_factory_pk(self):
with self.assertRaises(IntegrityError):
CollectionFactory(user=self.collection.user, name=self.collection.name)

def test_created_at_and_updated_at_nullable(self):
collection = Collection.objects.create(user=self.user)
self.assertIsNotNone(collection.created_at)
self.assertIsNotNone(collection.updated_at)

def test_created_at_and_updated_at_update(self):
collection = Collection.objects.create(user=self.user)
collection.name = "New Name"
collection.save()
self.assertIsNotNone(collection.updated_at)
11 changes: 11 additions & 0 deletions photo/tests/test_database/test_contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,14 @@ def test_factory_null(self):
def test_factory_pk(self):
with self.assertRaises(IntegrityError):
ContestFactory(id=self.contest.id)

def test_created_at_and_updated_at_nullable(self):
contest = Contest.objects.create(created_by=self.winners[0])
self.assertIsNotNone(contest.created_at)
self.assertIsNotNone(contest.updated_at)

def test_created_at_and_updated_at_update(self):
contest = Contest.objects.create(created_by=self.winners[0])
contest.title = "New Title"
contest.save()
self.assertIsNotNone(contest.updated_at)
10 changes: 10 additions & 0 deletions photo/tests/test_database/test_contest_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ def test_second_submission_same_user(self):
picture=PictureFactory(user=self.contest_submission.picture.user),
contest=self.contest_submission.contest,
)

def test_created_at_and_updated_at_nullable(self):
submission = ContestSubmission.objects.create(contest=self.contest_submission.contest, picture=self.contest_submission.picture)
self.assertIsNotNone(submission.created_at)
self.assertIsNotNone(submission.updated_at)

def test_created_at_and_updated_at_update(self):
submission = ContestSubmission.objects.create(contest=self.contest_submission.contest, picture=self.contest_submission.picture)
submission.save()
self.assertIsNotNone(submission.updated_at)
9 changes: 9 additions & 0 deletions photo/tests/test_database/test_picture.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ def test_factory(self):
for like in self.picture.likes.all():
self.assertTrue(User.objects.filter(email=like.email).exists())

def test_created_at_and_updated_at_nullable(self):
picture = Picture.objects.create(user=self.user)
self.assertIsNotNone(picture.created_at)
self.assertIsNotNone(picture.updated_at)

def test_created_at_and_updated_at_update(self):
picture = Picture.objects.create(user=self.user)
picture.save()
self.assertIsNotNone(picture.updated_at)

class PictureUploadTest(TestCase):
def setUp(self):
Expand Down
10 changes: 10 additions & 0 deletions photo/tests/test_database/test_picture_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ def test_factory_null(self):
def test_factory_pk(self):
with self.assertRaises(IntegrityError):
PictureCommentFactory(id=self.picture_comment.id)

def test_created_at_and_updated_at_nullable(self):
comment = PictureComment.objects.create(user=self.picture_comment.user, picture=self.picture_comment.picture)
self.assertIsNotNone(comment.created_at)
self.assertIsNotNone(comment.updated_at)

def test_created_at_and_updated_at_update(self):
comment = PictureComment.objects.create(user=self.picture_comment.user, picture=self.picture_comment.picture)
comment.save()
self.assertIsNotNone(comment.updated_at)
8 changes: 8 additions & 0 deletions photo/tests/test_queries/graphql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
pictures {
id
}
created_at
updated_at
}
}
"""
Expand Down Expand Up @@ -55,6 +57,8 @@
id
}
status
created_at
updated_at
}
}
"""
Expand Down Expand Up @@ -131,6 +135,8 @@
votes {
email
}
created_at
updated_at
}
}
"""
Expand Down Expand Up @@ -169,6 +175,8 @@
likes {
email
}
created_at
updated_at
}
}
"""
Expand Down
11 changes: 11 additions & 0 deletions photo/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class UserType:
profile_picture: "PictureType"
profile_picture_updated_at: strawberry.auto
user_handle: str
created_at: strawberry.auto
updated_at: strawberry.auto


@strawberry.django.type(Picture)
Expand All @@ -32,6 +34,8 @@ class PictureType:
name: str
file: str
likes: List[UserType]
created_at: strawberry.auto
updated_at: strawberry.auto


@strawberry.django.type(PictureComment)
Expand All @@ -42,13 +46,16 @@ class PictureCommentType:
text: str
created_at: strawberry.auto

updated_at: strawberry.auto

@strawberry.django.type(Collection)
class CollectionType:
id: int
name: str
user: "UserType"
pictures: List[PictureType]
created_at: strawberry.auto
updated_at: strawberry.auto


@strawberry.django.type(Contest)
Expand All @@ -67,6 +74,8 @@ class ContestType:
winners: List[UserType]
created_by: "UserType"
status: str
created_at: strawberry.auto
updated_at: strawberry.auto

@strawberry.field
def status(self) -> str:
Expand All @@ -92,6 +101,8 @@ class ContestSubmissionType:
picture: PictureType
submission_date: strawberry.auto
votes: List[UserType]
created_at: strawberry.auto
updated_at: strawberry.auto


@strawberry.type
Expand Down
Loading