Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleyzhang01 committed Oct 24, 2023
1 parent ac0c037 commit 1ad1954
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
10 changes: 9 additions & 1 deletion backend/sublet/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
from django.contrib import admin
from django.utils.html import escape, mark_safe

from sublet.models import Amenity, Favorite, Offer, Sublet, SubletImage

class SubletAdmin(admin.ModelAdmin):
def image_tag(self, instance):
images = ['<img src="%s" height="150" />' for image in instance.images.all()]
return mark_safe('<br>'.join(images))

image_tag.short_description = "Sublet Images"
readonly_fields = ("image_tag",)

admin.site.register(Offer)
admin.site.register(Amenity)
admin.site.register(Sublet)
admin.site.register(Sublet, SubletAdmin)
admin.site.register(SubletImage)
admin.site.register(Favorite)
25 changes: 25 additions & 0 deletions backend/sublet/migrations/0005_auto_20231024_1754.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.2.21 on 2023-10-24 21:54

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('sublet', '0004_alter_sublet_favorites'),
]

operations = [
migrations.AlterField(
model_name='sublet',
name='favorites',
field=models.ManyToManyField(blank=True, null=True, related_name='sublets_favorited', through='sublet.Favorite', to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='sublet',
name='sublettees',
field=models.ManyToManyField(blank=True, null=True, related_name='sublets_offered', through='sublet.Offer', to=settings.AUTH_USER_MODEL),
),
]
8 changes: 4 additions & 4 deletions backend/sublet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class Sublet(models.Model):
) # TODO: not sure if anything else should go into this as params

title = models.CharField(max_length=255)
address = models.CharField(max_length=255)
beds = models.IntegerField()
baths = models.IntegerField()
description = models.TextField()
address = models.CharField(max_length=255, null=True, blank=True)
beds = models.IntegerField(null=True, blank=True)
baths = models.IntegerField(null=True, blank=True)
description = models.TextField(null=True, blank=True)
external_link = models.URLField(max_length=255)
min_price = models.IntegerField()
max_price = models.IntegerField()
Expand Down
13 changes: 6 additions & 7 deletions backend/sublet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
SimpleSubletSerializer,
)

from .serializers import SubletSerializer


User = get_user_model()

Expand Down Expand Up @@ -75,11 +73,12 @@ class Properties(viewsets.ModelViewSet):

def get_queryset(self):
# All Sublets for superusers
if self.request.user.is_superuser:
return Sublet.objects.all()
# if self.request.user.is_superuser:
# return Sublet.objects.all()

# All Sublets where expires_at hasn't passed yet for regular users
return Sublet.objects.filter(expires_at__gte=timezone.now())
# # All Sublets where expires_at hasn't passed yet for regular users
# return Sublet.objects.filter(expires_at__gte=timezone.now())
return Sublet.objects.all()

def create(self, request, *args, **kwargs):
amenities = request.data.pop("amenities", [])
Expand Down Expand Up @@ -113,7 +112,7 @@ def list(self, request, *args, **kwargs):
beds = request.query_params.get("beds", None)
baths = request.query_params.get("baths", None)

queryset = Sublet.objects.all()
queryset = Sublet.objects.all(expires_at__gte=timezone.now())

# Apply filters based on query parameters
if amenities:
Expand Down

0 comments on commit 1ad1954

Please sign in to comment.