room specific factoids

This commit is contained in:
Nils Büchner 2024-06-08 19:26:35 +02:00
parent 1784b0343e
commit c5bb29d1f1
4 changed files with 7 additions and 4 deletions

View file

@ -4,9 +4,9 @@ from .models import Fact
from .forms import FactForm
class FactAdmin(admin.ModelAdmin):
list_display = ('name', 'value', 'ftype', 'create_date', 'change_date', 'author', 'popularity')
list_filter = ('ftype', 'create_date', 'author') # Fields to add filters for
search_fields = ('name', 'value')
list_display = ('name', 'value', 'ftype', 'create_date', 'change_date', 'room', 'author', 'popularity')
list_filter = ('ftype', 'create_date', 'author', 'room') # Fields to add filters for
search_fields = ('name', 'value', 'room')
form = FactForm
def get_form(self, request, obj=None, **kwargs):
# Check if an instance is being added (obj is None) to exclude 'author_id' field

View file

@ -24,6 +24,7 @@ class Fact(models.Model):
id = models.BigAutoField(primary_key=True)
author = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
room = models.CharField(null=True, default=None, max_length=128)
create_date = models.DateTimeField("date published", default=timezone.now)
change_date = models.DateTimeField("date changed", default=timezone.now)
popularity = models.IntegerField(default=0)

View file

@ -10,7 +10,7 @@ class FactSerializer(serializers.ModelSerializer):
user_ids = serializers.SerializerMethodField()
class Meta:
model = Fact
fields = ['id', 'name', 'user_ids', 'value', 'ftype', 'author_name', 'create_date', 'change_date', 'popularity']
fields = ['id', 'name', 'user_ids', 'value', 'ftype', 'room', 'author_name', 'create_date', 'change_date', 'popularity']
def get_author_name(self, obj):
# Assuming the author field can be null

View file

@ -21,6 +21,7 @@
<th><a href="?sort=name">Name</a></th>
<th>Value</th>
<th>Type</th>
<th>Room</th>
<th>Author</th>
<th><a href="?sort=popularity">Popularity</a></th>
</tr>
@ -31,6 +32,7 @@
<td>{{ fact.name }}</td>
<td class="expandable">{{ fact.value }}</td>
<td>{{ fact.get_ftype_display }}</td>
<td>{% if fact.room %}{{ fact.room }}{% else %}all{% endif %}</td>
<td>{% if fact.author %}{{ fact.author.username }}{% else %}N/A{% endif %}</td>
<td>{{ fact.popularity }}</td>
</tr>