From 0d3f1c3733801fbb40aaf080565a10f398847e7c Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 2 Aug 2024 17:33:44 +0200 Subject: [PATCH] feat: add Offer model and migration Introduce the Offer model to manage domain purchase offers. The new model includes fields for offered price, messages, intended use, and status with choices for 'pending', 'accepted', and 'rejected', linked to both the Domain and User models. Updated URLs to support offer creation and listing. This change facilitates better tracking and management of offers made on domains, enabling more robust domain transactions. --- .../domains/migrations/0004_offer.py | 65 +++++++++++++++++++ caffeinateddomains/domains/models.py | 21 ++++++ caffeinateddomains/domains/urls.py | 4 +- 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 caffeinateddomains/domains/migrations/0004_offer.py diff --git a/caffeinateddomains/domains/migrations/0004_offer.py b/caffeinateddomains/domains/migrations/0004_offer.py new file mode 100644 index 0000000..37e0e46 --- /dev/null +++ b/caffeinateddomains/domains/migrations/0004_offer.py @@ -0,0 +1,65 @@ +# Generated by Django 5.0.7 on 2024-08-02 15:33 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ( + "domains", + "0003_domain_accept_offers_domain_additional_info_request_and_more", + ), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="Offer", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("offered_price", models.DecimalField(decimal_places=2, max_digits=10)), + ("message", models.TextField(blank=True, null=True)), + ("intended_use", models.TextField(blank=True, null=True)), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "status", + models.CharField( + choices=[ + ("pending", "Pending"), + ("accepted", "Accepted"), + ("rejected", "Rejected"), + ], + default="pending", + max_length=20, + ), + ), + ( + "domain", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="offers", + to="domains.domain", + ), + ), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="offers", + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + ] diff --git a/caffeinateddomains/domains/models.py b/caffeinateddomains/domains/models.py index eb8820b..631252c 100644 --- a/caffeinateddomains/domains/models.py +++ b/caffeinateddomains/domains/models.py @@ -29,6 +29,27 @@ class Domain(models.Model): return self.name +class Offer(models.Model): + domain = models.ForeignKey(Domain, on_delete=models.CASCADE, related_name="offers") + user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="offers") + offered_price = models.DecimalField(max_digits=10, decimal_places=2) + message = models.TextField(blank=True, null=True) + intended_use = models.TextField(blank=True, null=True) + created_at = models.DateTimeField(auto_now_add=True) + status = models.CharField( + max_length=20, + choices=[ + ("pending", "Pending"), + ("accepted", "Accepted"), + ("rejected", "Rejected"), + ], + default="pending", + ) + + def __str__(self): + return f"Offer for {self.domain.name} by {self.user.email}" + + class DNSRecord(models.Model): RECORD_TYPE_CHOICES = [ ("A", "A"), diff --git a/caffeinateddomains/domains/urls.py b/caffeinateddomains/domains/urls.py index 2a16df8..d28e6d8 100644 --- a/caffeinateddomains/domains/urls.py +++ b/caffeinateddomains/domains/urls.py @@ -2,6 +2,6 @@ from django.urls import path from .views import DomainListCreateView, OfferListCreateView urlpatterns = [ - path('domains/', DomainListCreateView.as_view(), name='domain_list_create'), - path('offers/', OfferListCreateView.as_view(), name='offer_list_create'), + path("domains/", DomainListCreateView.as_view(), name="domain_list_create"), + path("offers/", OfferListCreateView.as_view(), name="offer_list_create"), ]