Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david1542/6f783795ed9b9fa43bfc0177c7ab5504 to your computer and use it in GitHub Desktop.
Save david1542/6f783795ed9b9fa43bfc0177c7ab5504 to your computer and use it in GitHub Desktop.
Djongo Models
from djongo import models
from django import forms
userStatusEnum = (
('pending', 'pending'),
('active', 'active'),
('removed', 'removed'),
)
userTypeEnum = (
('buyer', 'buyer'),
('supplier', 'supplier'),
('admin', 'admin'),
)
genderEnum = (
('male', 'male'),
('female', 'female'),
('other', 'other'),
)
termsEnum = (
('Cash', 'Cash'),
('30 Days', '30 Days'),
('60 Days', '60 Days'),
('90 Days', '90 Days'),
('120 Days', '120 Days'),
)
statusEnum = (
('Pending', 'Pending'),
('Approved', 'Approved'),
('Disapproved', 'Disapproved'),
)
permissionsEnum = (
('default', 'default'),
)
class User(models.Model):
_id = models.ObjectIdField()
email = models.EmailField()
password = models.CharField(max_length=200)
firstName = models.TextField()
lastName = models.TextField()
displayName = models.CharField(max_length=16, null=True, blank=True)
address = models.TextField(null=True, blank=True)
status = models.CharField(max_length=20, choices=userStatusEnum)
gender = models.CharField(max_length=10, blank=True, choices=genderEnum)
userType = models.CharField(max_length=20, choices=userTypeEnum)
# supplier = models.ForeignKey('Supplier', blank=True, unique=True, on_delete=None)
buyer = models.ForeignKey('Buyer', unique=True, blank=True, on_delete=None)
admin = models.ForeignKey('Admin', unique=True, blank=True, on_delete=None, related_name='Admin')
class Meta:
db_table = 'users'
class Supplier(models.Model):
_id = models.ObjectIdField()
userId = models.ForeignKey('User', null=False, on_delete=None, related_name='userId', db_column='userId')
boxes = models.ForeignKey('Box', on_delete=models.CASCADE, related_name='boxes', db_column='boxes')
newBids = models.IntegerField()
class Meta:
db_table = 'suppliers'
def __unicode__(self):
return 'Supplier'
class Box(models.Model):
_id = models.ObjectIdField()
description = models.TextField()
producer = models.TextField()
cycle = models.DateField()
owner = models.ForeignKey(Supplier, unique=True, on_delete=models.CASCADE, db_column='owner')
event = models.ForeignKey('Event', unique=True, on_delete=None)
type = models.TextField()
creditTerms = models.CharField(max_length=10, choices=termsEnum)
bids = models.ForeignKey(Bid, on_delete=models.CASCADE, related_name='Bid', blank=True)
looking = models.ForeignKey('User', on_delete=models.CASCADE, blank=True)
sold = models.BooleanField()
paid = models.BooleanField()
delivered = models.BooleanField()
sealed = models.BooleanField()
withdrawn = models.BooleanField()
initialPrice = models.FloatField()
value = models.FloatField()
cts = models.FloatField()
ppc = models.FloatField()
finalPrice = models.FloatField()
class Meta:
db_table = 'boxes'
verbose_name = 'Box'
verbose_name_plural = 'Boxes'
def __str__(self):
return "{}, Cycle - {}".format(self.type, self.cycle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment