class User(AbstractUser): height = models.IntegerField(blank=True, null=True) weight = models.IntegerField(blank=True, null=True) sex = models.CharField(max_length=50) age = computed_property.ComputedIntegerField(compute_from='get_age', blank=True, null=True) birth_date = models.DateField(blank=True, null=True) useractivity = models.IntegerField(blank=True, null=True) bmi = computed_property.ComputedIntegerField(compute_from='get_bmi', blank=True, null=True) bloodtype = models.CharField(max_length=50, blank=True, null=True, choices=(("a", "A"), ("b", "B"), ("ab", "AB"), ("o", "O"))) dci = models.IntegerField(blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) def __str__(self): return self.email def get_bmi(self): return calculate_bmi(self.height, self.weight) def get_age(self): return calculate_age(self.birth_date)
class Post(models.Model): Post = 'Post' body = models.CharField(max_length=280) created_at = models.DateTimeField(auto_now_add=True) upvotes = models.IntegerField(default=0) downvotes = models.IntegerField(default=0) score = computed_property.ComputedIntegerField(compute_from='get_score') @property def get_score(self): vote_score = self.upvotes - self.downvotes return vote_score def __str__(self): return self.body # class Comment(models.Model): # post = models.ForeignKey(Post, related_name='comments', on_delete=models.CASCADE) # # user = models.CharField(max_length=200) # email = models.EmailField() # body = models.TextField() # created_date = models.DateTimeField(default=timezone.now) # # approved = models.BooleanField(default=False) # # def approved(self): # # self.approved = True # # self.save() # def __str__(self): # return self.body
class Orders(models.Model): #product = models.CharField(max_length=100) product = models.ManyToManyField(Products) User = get_user_model() cust = models.ForeignKey(User, related_name='prodorders', on_delete=models.CASCADE) #cust = models.ForeignKey('Users.User',related_name='prodorders',on_delete=models.CASCADE) totalprice = computed_property.ComputedIntegerField( compute_from='calcprice') orderquantity = models.IntegerField(default=1) class Meta: ordering = ['orderquantity'] def calcprice(self): if Products.objects.get( name=self.product).quantity >= self.orderquantity: v = Products.objects.get(name=self.product) v.quantity = v.quantity - self.orderquantity v.save() return self.orderquantity * Products.objects.get( name=self.product).price else: return 0
class Post(models.Model): Boast = 'Boast' Roast = 'Roast' POST_CHOICES = [(Boast, 'Boast'), (Roast, 'Roast')] text = models.CharField(max_length=280) post_time = models.DateTimeField(auto_now_add=True) upvotes = models.IntegerField(default=0) downvotes = models.IntegerField(default=0) post_choice = models.CharField(choices=POST_CHOICES, default=Boast, max_length=6) score = computed_property.ComputedIntegerField(compute_from='get_score') @property def get_score(self): vote_score = self.upvotes - self.downvotes return vote_score def __str__(self): return self.text
class Album(models.Model): class Genre(models.TextChoices): ROCK = 'Rock', _('Rock') HIPHOP = 'HipHop', _('HipHop'), RHYTHMANDBLUES = 'R&B', _('R&B'), FUNK = 'Funk', _('Funk'), SOUL = 'Soul', _('Soul'), COUNTRY = 'Country', _('Country'), POP = 'Pop', _('Pop'), ELECTRONIC = 'Electronic', _('Electronic'), JAZZ = 'Jazz', _('Jazz'), FOLK = 'Folk', _('Folk'), MISCELLANEOUS = 'Miscellaneous', _('Miscellaneous') genre_choice = models.CharField( max_length=30, choices=Genre.choices, default=Genre.MISCELLANEOUS ) wishlist = models.ManyToManyField(CustomUser, related_name='wishlist+', symmetrical=False, blank=True) title = models.CharField(max_length=100) artist = models.CharField(max_length=50) artwork = models.ImageField(upload_to='images/', null=True, blank=True) post_date = models.DateTimeField(default=datetime.datetime.now()) description = models.TextField(max_length=None, blank=False) uploaded_by = models.ForeignKey(CustomUser, on_delete=models.DO_NOTHING, ) total_ratings = computed_property.ComputedIntegerField( default=0, compute_from='get_total_ratings' ) average_rating = computed_property.ComputedIntegerField( default=0, compute_from='get_average_rating' ) def save(self, *args, **kwargs): if not self.total_ratings: self.total_ratings = self.get_total_ratings() if not self.average_rating: self.average_rating = self.get_average_rating() super(Album, self).save(*args, **kwargs) def get_total_ratings(self): all_ratings = Rating.objects.filter(album=self) return len(all_ratings) def get_average_rating(self): sum = 0 ratings_average = Rating.objects.filter(album=self) for rating in ratings_average: sum += rating.stars if len(ratings_average) > 0: return sum / len(ratings_average) else: return 0 def __str__(self): return f'{self.title} by {self.artist} uploaded by {self.uploaded_by}'
class Well_Data(models.Model): data_well_name = models.ForeignKey(Well_Profile, on_delete=models.CASCADE) #data_date = models.DateTimeField() data_hour = models.IntegerField() data_tubing_psi = models.IntegerField() data_csg_psi = models.IntegerField() data_choke_size = models.IntegerField() data_sep_psi = models.IntegerField() data_oil_rate = models.IntegerField() data_water_rate = models.IntegerField() data_gas_rate = models.IntegerField() data_flowline_psi = models.IntegerField() data_chlorides = models.IntegerField() data_sand_percent = models.IntegerField() data_h2s = models.IntegerField() data_remarks = models.CharField(max_length=300, default="") def __str__(self): return "%s%s%s" % (str( self.data_well_name), " flowback hour= ", str(self.data_hour)) #return "%s%s%s" % (str(self.data_well_name), " flowback hour= ", str(self.data_hour)) #compute_property methology oil_bpd = computed_property.ComputedIntegerField(compute_from='oil_24') def oil_24(self): return self.data_oil_rate * 24 water_bpd = computed_property.ComputedIntegerField(compute_from='water_24') def water_24(self): return self.data_water_rate * 24 total_fluid_bpd = computed_property.ComputedIntegerField( compute_from='calc_total_fluid_daily') def calc_total_fluid_daily(self): return (self.data_oil_rate * 24 + self.data_water_rate * 24) total_fluid_bph = computed_property.ComputedIntegerField( compute_from='calc_total_fluid_daily') def calc_total_fluid_daily(self): return (self.data_oil_rate * 24 + self.data_water_rate * 24) gas_oil_ratio = computed_property.ComputedIntegerField( compute_from='calc_gor') def calc_gor(self): return (self.data_gas_rate) / (self.data_oil_rate * 24) * 1000 water_cut = computed_property.ComputedIntegerField( compute_from='calc_wcut') def calc_wcut(self): return ((self.data_water_rate) / ((self.data_oil_rate) + (self.data_water_rate))) * 100 def calc_name_hour(self): return "%s%s%s" % (str( self.data_well_name), " flowback hour= ", str(self.data_hour))
class ComputedNullable(models.Model): computed = fields.ComputedIntegerField(null=True, compute_from=lambda x: None)
class ComputedInt(AbstractInt): computed = fields.ComputedIntegerField(compute_from='compute_val')