Skip to content

Commit

Permalink
Use a BaseModel
Browse files Browse the repository at this point in the history
  • Loading branch information
normade committed Jan 26, 2024
1 parent af595b7 commit 9aa8ef6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
12 changes: 4 additions & 8 deletions mia_buildings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.utils.safestring import mark_safe
from django.utils.text import slugify

from modernism.models import BaseModel


class Feature(models.Model):
name = models.CharField(max_length=254, unique=True)
Expand Down Expand Up @@ -63,10 +65,7 @@ class Meta:
verbose_name_plural = "Access types"


class BuildingImage(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

class BuildingImage(BaseModel):
image = models.ImageField(upload_to="original_images", null=True, blank=True)
building = models.ForeignKey(
"mia_buildings.Building", on_delete=models.SET_NULL, null=True, blank=True
Expand Down Expand Up @@ -95,10 +94,7 @@ def image_preview(self):
return "(No image)"


class Building(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

class Building(BaseModel):
name = models.CharField(max_length=254, unique=True)
name_addition = models.CharField(
max_length=254,
Expand Down
16 changes: 5 additions & 11 deletions mia_facts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.utils.text import slugify
from unidecode import unidecode

from modernism.models import BaseModel


class Country(models.Model):
name = models.CharField(max_length=100, unique=True)
Expand Down Expand Up @@ -61,14 +63,12 @@ def __str__(self):
return name


class Source(models.Model):
class Source(BaseModel):
class SourceType(models.TextChoices):
WEBSITE = "WE", "Website"
BOOK = "BK", "Book"
JOURNAL = "JL", "Journal"

created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
source_type = models.CharField(
max_length=2,
choices=SourceType.choices,
Expand Down Expand Up @@ -97,10 +97,7 @@ class Meta:
verbose_name_plural = "Categories"


class FactImage(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

class FactImage(BaseModel):
image = models.ImageField(upload_to="mia-facts", null=True, blank=True)
fact = models.ForeignKey(
"mia_facts.Fact", on_delete=models.SET_NULL, null=True, blank=True
Expand All @@ -115,10 +112,7 @@ def __str__(self):
return f"{self.title if self.title else self.pk}"


class Fact(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

class Fact(BaseModel):
title = models.CharField(max_length=250, unique=True)
description = models.TextField(blank=True)
categories = models.ManyToManyField("mia_facts.FactCategory", blank=True)
Expand Down
9 changes: 9 additions & 0 deletions modernism/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models


class BaseModel(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

class Meta:
abstract = True

0 comments on commit 9aa8ef6

Please sign in to comment.