room specific factoids
This commit is contained in:
parent
1784b0343e
commit
c5bb29d1f1
4 changed files with 7 additions and 4 deletions
|
@ -4,9 +4,9 @@ from .models import Fact
|
||||||
from .forms import FactForm
|
from .forms import FactForm
|
||||||
|
|
||||||
class FactAdmin(admin.ModelAdmin):
|
class FactAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'value', 'ftype', 'create_date', 'change_date', 'author', 'popularity')
|
list_display = ('name', 'value', 'ftype', 'create_date', 'change_date', 'room', 'author', 'popularity')
|
||||||
list_filter = ('ftype', 'create_date', 'author') # Fields to add filters for
|
list_filter = ('ftype', 'create_date', 'author', 'room') # Fields to add filters for
|
||||||
search_fields = ('name', 'value')
|
search_fields = ('name', 'value', 'room')
|
||||||
form = FactForm
|
form = FactForm
|
||||||
def get_form(self, request, obj=None, **kwargs):
|
def get_form(self, request, obj=None, **kwargs):
|
||||||
# Check if an instance is being added (obj is None) to exclude 'author_id' field
|
# Check if an instance is being added (obj is None) to exclude 'author_id' field
|
||||||
|
|
|
@ -24,6 +24,7 @@ class Fact(models.Model):
|
||||||
|
|
||||||
id = models.BigAutoField(primary_key=True)
|
id = models.BigAutoField(primary_key=True)
|
||||||
author = models.ForeignKey(User, on_delete=models.SET_NULL, null=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)
|
create_date = models.DateTimeField("date published", default=timezone.now)
|
||||||
change_date = models.DateTimeField("date changed", default=timezone.now)
|
change_date = models.DateTimeField("date changed", default=timezone.now)
|
||||||
popularity = models.IntegerField(default=0)
|
popularity = models.IntegerField(default=0)
|
||||||
|
|
|
@ -10,7 +10,7 @@ class FactSerializer(serializers.ModelSerializer):
|
||||||
user_ids = serializers.SerializerMethodField()
|
user_ids = serializers.SerializerMethodField()
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Fact
|
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):
|
def get_author_name(self, obj):
|
||||||
# Assuming the author field can be null
|
# Assuming the author field can be null
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
<th><a href="?sort=name">Name</a></th>
|
<th><a href="?sort=name">Name</a></th>
|
||||||
<th>Value</th>
|
<th>Value</th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
|
<th>Room</th>
|
||||||
<th>Author</th>
|
<th>Author</th>
|
||||||
<th><a href="?sort=popularity">Popularity</a></th>
|
<th><a href="?sort=popularity">Popularity</a></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
<td>{{ fact.name }}</td>
|
<td>{{ fact.name }}</td>
|
||||||
<td class="expandable">{{ fact.value }}</td>
|
<td class="expandable">{{ fact.value }}</td>
|
||||||
<td>{{ fact.get_ftype_display }}</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>{% if fact.author %}{{ fact.author.username }}{% else %}N/A{% endif %}</td>
|
||||||
<td>{{ fact.popularity }}</td>
|
<td>{{ fact.popularity }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Loading…
Reference in a new issue