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.
This commit is contained in:
Kumi 2024-08-02 17:33:44 +02:00
parent 1e1b590803
commit 0d3f1c3733
Signed by: kumi
GPG key ID: ECBCC9082395383F
3 changed files with 88 additions and 2 deletions

View file

@ -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,
),
),
],
),
]

View file

@ -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"),

View file

@ -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"),
]