Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minghan market two routes #318

Open
wants to merge 16 commits into
base: create-market-from-sublet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions backend/market/admin.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from django.contrib import admin
from django.utils.html import mark_safe

from market.models import Amenity, Offer, Sublet, SubletImage
from market.models import Category, Item, ItemImage, Offer, Sublet, Tag


class SubletAdmin(admin.ModelAdmin):
class ItemAdmin(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"
image_tag.short_description = "Item Images"
readonly_fields = ("image_tag",)


admin.site.register(Offer)
admin.site.register(Amenity)
admin.site.register(Sublet, SubletAdmin)
admin.site.register(SubletImage)
admin.site.register(Tag)
admin.site.register(Category)
admin.site.register(Item, ItemAdmin)
admin.site.register(Sublet)
admin.site.register(ItemImage)
168 changes: 168 additions & 0 deletions backend/market/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Generated by Django 5.0.2 on 2024-10-25 16:41

import django.db.models.deletion
import phonenumber_field.modelfields
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="Category",
fields=[
("name", models.CharField(max_length=50, primary_key=True, serialize=False)),
],
),
migrations.CreateModel(
name="Tag",
fields=[
("name", models.CharField(max_length=255, primary_key=True, serialize=False)),
],
),
migrations.CreateModel(
name="Item",
fields=[
(
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("title", models.CharField(max_length=255)),
("description", models.TextField(blank=True, null=True)),
("external_link", models.URLField(blank=True, max_length=255, null=True)),
("price", models.IntegerField()),
("negotiable", models.BooleanField(default=True)),
("used", models.BooleanField(blank=True, null=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
("expires_at", models.DateTimeField()),
(
"category",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="items",
to="market.category",
),
),
(
"favorites",
models.ManyToManyField(
blank=True, related_name="items_favorited", to=settings.AUTH_USER_MODEL
),
),
(
"seller",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
),
),
],
),
migrations.CreateModel(
name="ItemImage",
fields=[
(
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("image", models.ImageField(upload_to="marketplace/images")),
(
"item",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="images",
to="market.item",
),
),
],
),
migrations.CreateModel(
name="Offer",
fields=[
(
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("email", models.EmailField(blank=True, max_length=255, null=True)),
(
"phone_number",
phonenumber_field.modelfields.PhoneNumberField(
blank=True, max_length=128, null=True, region=None
),
),
("message", models.CharField(blank=True, max_length=255)),
("created_date", models.DateTimeField(auto_now_add=True)),
(
"item",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="offers",
to="market.item",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="offers_made_market",
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.AddField(
model_name="item",
name="buyers",
field=models.ManyToManyField(
blank=True,
related_name="items_offered",
through="market.Offer",
to=settings.AUTH_USER_MODEL,
),
),
migrations.CreateModel(
name="Sublet",
fields=[
(
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("address", models.CharField(max_length=255)),
("beds", models.IntegerField()),
("baths", models.IntegerField()),
("start_date", models.DateTimeField()),
("end_date", models.DateTimeField()),
(
"item",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="sublet",
to="market.item",
),
),
],
),
migrations.AddField(
model_name="item",
name="tags",
field=models.ManyToManyField(blank=True, related_name="items", to="market.tag"),
),
migrations.AddConstraint(
model_name="offer",
constraint=models.UniqueConstraint(fields=("user", "item"), name="unique_offer_market"),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.2 on 2024-10-25 21:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("market", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name="item",
name="used",
),
migrations.AlterField(
model_name="item",
name="price",
field=models.FloatField(),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 5.0.2 on 2024-11-02 22:49

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


class Migration(migrations.Migration):

dependencies = [
("market", "0002_remove_item_used_alter_item_price"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterField(
model_name="item",
name="category",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="market.category"
),
),
migrations.AlterField(
model_name="item",
name="seller",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="items_listed",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AlterField(
model_name="item",
name="tags",
field=models.ManyToManyField(blank=True, to="market.tag"),
),
migrations.AlterField(
model_name="itemimage",
name="item",
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="market.item"),
),
migrations.AlterField(
model_name="offer",
name="item",
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="market.item"),
),
migrations.AlterField(
model_name="offer",
name="user",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
),
),
]
18 changes: 18 additions & 0 deletions backend/market/migrations/0004_rename_image_itemimage_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-11-08 23:07

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("market", "0003_alter_item_category_alter_item_seller_and_more"),
]

operations = [
migrations.RenameField(
model_name="itemimage",
old_name="image",
new_name="images",
),
]
18 changes: 18 additions & 0 deletions backend/market/migrations/0005_rename_images_itemimage_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-11-08 23:10

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("market", "0004_rename_image_itemimage_images"),
]

operations = [
migrations.RenameField(
model_name="itemimage",
old_name="images",
new_name="image",
),
]
21 changes: 21 additions & 0 deletions backend/market/migrations/0006_alter_itemimage_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.2 on 2024-11-08 23:11

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("market", "0005_rename_images_itemimage_image"),
]

operations = [
migrations.AlterField(
model_name="itemimage",
name="item",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="images", to="market.item"
),
),
]
Loading
Loading