Skip to content

Commit

Permalink
feat: hide read only audit fields from admin
Browse files Browse the repository at this point in the history
  • Loading branch information
ngurenyaga committed Jul 14, 2021
1 parent ec7805d commit 24ed9d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pepfar_mle/common/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@


class BaseAdmin(admin.ModelAdmin):
readonly_fields = (
"created",
"created_by",
"updated",
"updated_by",
)

def save_model(self, request, obj, form, change):
if not change:
obj.created_by = request.user.pk
Expand Down
18 changes: 18 additions & 0 deletions pepfar_mle/common/migrations/0005_auto_20210714_1633.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.12 on 2021-07-14 13:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('common', '0004_auto_20210714_1339'),
]

operations = [
migrations.AlterField(
model_name='facilityattachment',
name='size',
field=models.IntegerField(blank=True, help_text='The size of the attachment in bytes', null=True),
),
]
7 changes: 6 additions & 1 deletion pepfar_mle/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ class Attachment(AbstractBase):
data = models.FileField(upload_to=get_directory, max_length=65535)
title = models.CharField(max_length=255)
creation_date = models.DateTimeField(default=timezone.now)
size = models.IntegerField(help_text="The size of the attachment in bytes")
size = models.IntegerField(
help_text="The size of the attachment in bytes", null=True, blank=True
)
description = models.TextField(null=True, blank=True)
aspect_ratio = models.CharField(max_length=50, blank=True, null=True)

Expand All @@ -328,7 +330,10 @@ def validate_image_size(self):
"""Ensure that the supplied image size matches the actual file."""
if not is_image_type(self.content_type):
return

image = Image.open(self.data)
self.size = len(image.fp.read())

width, height = image.size
msg_template = (
"Your image has a {axis} of {actual_size} {extra_text} "
Expand Down

0 comments on commit 24ed9d5

Please sign in to comment.