Skip to content

Commit

Permalink
Update user and unit models (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
ltan02 authored Oct 25, 2023
1 parent 39b6c0a commit bf54019
Show file tree
Hide file tree
Showing 14 changed files with 399 additions and 235 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ To get a local copy up and running follow these simple steps.
#### Django Backend

1. `cd` into backend folder
2. run `pipenv install` to install dependencies
3. run `pipenv shell` to enter virtual environment
4. run `pipenv run start`
2. Make a copy of sample.env, rename it to .env, and fill out the environment variables.
3. run `pipenv install` to install dependencies
4. run `pipenv shell` to enter virtual environment
5. run `pipenv run start`

#### NextJS Frontend

Expand Down
8 changes: 0 additions & 8 deletions backend/auction/admin.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
from django.contrib import admin

from auction.models import Auction
from bid.models import Bid
from user.models import User
from vehicle.models import Brand, Vehicle, VehicleType

# Register your models here.
admin.site.register(Auction)
admin.site.register(Vehicle)
admin.site.register(Brand)
admin.site.register(VehicleType)
admin.site.register(Bid)
admin.site.register(User)
24 changes: 11 additions & 13 deletions backend/auction/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Generated by Django 4.2.5 on 2023-10-07 23:50

import uuid
# Generated by Django 4.2.6 on 2023-10-24 19:15

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):
Expand All @@ -16,20 +15,19 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
verbose_name="ID",
unique=True,
),
),
(
"identifier",
models.UUIDField(default=uuid.uuid4, editable=False, unique=True),
),
("created_at", models.DateTimeField(editable=False)),
("updated_at", models.DateTimeField()),
("end_date", models.DateTimeField(editable=False)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("name", models.CharField(max_length=150)),
("start_date", models.DateTimeField()),
("end_date", models.DateTimeField()),
],
options={
"ordering": ["-created_at"],
Expand Down

This file was deleted.

3 changes: 3 additions & 0 deletions backend/bid/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.contrib import admin

from .models import Bid

# Register your models here.
admin.site.register(Bid)
31 changes: 14 additions & 17 deletions backend/bid/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Generated by Django 4.2.5 on 2023-10-07 23:50
# Generated by Django 4.2.6 on 2023-10-24 19:21

import uuid

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


class Migration(migrations.Migration):
initial = True

dependencies = [
("contenttypes", "0002_remove_content_type_name"),
("user", "__first__"),
("vehicle", "0001_initial"),
]

operations = [
Expand All @@ -20,31 +19,29 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
verbose_name="ID",
unique=True,
),
),
(
"identifier",
models.UUIDField(default=uuid.uuid4, editable=False, unique=True),
),
("created_at", models.DateTimeField(editable=False)),
("updated_at", models.DateTimeField()),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("amount", models.IntegerField()),
("object_id", models.UUIDField()),
(
"bidder",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT, to="user.user"
on_delete=django.db.models.deletion.PROTECT, to="user.bidder"
),
),
(
"vehicle",
"content_type",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="vehicle.vehicle",
to="contenttypes.contenttype",
),
),
],
Expand Down
28 changes: 0 additions & 28 deletions backend/bid/migrations/0002_remove_bid_identifier_alter_bid_id.py

This file was deleted.

15 changes: 11 additions & 4 deletions backend/bid/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models

from core.models import MainModel
from user.models import User
from vehicle.models import Vehicle
from user.models import Bidder


class Bid(MainModel):
"""
created_at field on MainModel will be used to determine when the bid was
"""

amount = models.IntegerField(null=False)
vehicle = models.ForeignKey(Vehicle, on_delete=models.PROTECT)
bidder = models.ForeignKey(User, on_delete=models.PROTECT)
bidder = models.ForeignKey(Bidder, on_delete=models.PROTECT)
content_type = models.ForeignKey(ContentType, on_delete=models.PROTECT)
object_id = models.UUIDField()
content_object = GenericForeignKey("content_type", "object_id")
4 changes: 4 additions & 0 deletions backend/user/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from django.contrib import admin

from .models import Admin, Bidder

# Register your models here.
admin.site.register(Admin)
admin.site.register(Bidder)
45 changes: 36 additions & 9 deletions backend/user/models.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
import random

from django.db import models

from core.models import MainModel


# Create your models here.
class User(MainModel):
"""
The model used for handling users, this includes bidders and admins.
A user will become a bidder if their manytomanyfield contains the
auction in question. An auction will have many bidders, and a bidder
will be in many auctions.
class Admin(MainModel):
email = models.CharField(max_length=150, null=False)
password = models.CharField(max_length=50, null=False)
first_name = models.CharField(max_length=150, null=False)
last_name = models.CharField(max_length=150, null=False)
permission_level = models.IntegerField(default=0)

def __str__(self):
return f"Admin: {self.first_name} {self.last_name}"

"""

name = models.CharField(max_length=150, null=False)
class Bidder(MainModel):
email = models.CharField(max_length=150, null=False)
auction = models.ManyToManyField("auction.Auction", related_name="auction")
password = models.CharField(max_length=50, null=False)
first_name = models.CharField(max_length=150, null=False)
last_name = models.CharField(max_length=150, null=False)
company_name = models.CharField(max_length=150)
bidder_number = models.IntegerField(unique=True, null=False)
is_verified = models.BooleanField(default=False)
is_blacklisted = models.BooleanField(default=False)

def save(self, *args, **kwargs):
# Check if the bidder_number is not set yet
if not self.bidder_number:
# Generate a unique 8-digit number
bidder_number = self.generate_unique_bidder_number()
self.bidder_number = bidder_number
super(Bidder, self).save(*args, **kwargs)

def generate_unique_bidder_number(self):
# Generate an 8-digit number and check if it's unique
while True:
bidder_number = random.randint(10000000, 99999999)
if not Bidder.objects.filter(bidder_number=bidder_number).exists():
return bidder_number

def __str__(self):
return f"Bidder: {self.first_name} {self.last_name}"
10 changes: 10 additions & 0 deletions backend/vehicle/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
from django.contrib import admin

from .models import (
Brand, Equipment, Supplier, Trailer, Type, UnitImage, Vehicle)

# Register your models here.
admin.site.register(Brand)
admin.site.register(Type)
admin.site.register(Vehicle)
admin.site.register(Equipment)
admin.site.register(Supplier)
admin.site.register(Trailer)
admin.site.register(UnitImage)
Loading

0 comments on commit bf54019

Please sign in to comment.